×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Insert space char into results

Insert space char into results

Insert space char into results

(OP)
Hi guys,

I am trying to find a way to insert a space to seperate the first name and last name in my column when I query the db,

currently my data is displayed this way:

Abauer
Jjones
Asmith

and I would like it this way:

A Bauer
J Jones
A Smith

Is it possible to execute this in a query.


 

RE: Insert space char into results

Use the SQL string functions.
For example this works for me on DB2 UDB

CODE

with names (name) as (                                
  select 'Abauer'                                     
  from sysibm.sysdummy1 union all                     
  select 'Jjones'                                     
  from sysibm.sysdummy1 union all                     
  select 'Asmith'                                     
  from sysibm.sysdummy1)                              
select                                                
  name,                                               
  left(name,1) concat ' ' concat                      
  upper(left(substr(name,2,length(name)-1),1)) concat
  substr(name,3,length(name)-2) as name_new           
from names
result

CODE

....+....1....+....2....+..    
NAME    NAME_NEW               
Abauer  A Bauer                
Jjones  J Jones                
Asmith  A Smith                
********  End of data  ********

RE: Insert space char into results

(OP)

yeah mikrom that is what I am going for but without having to manually insert the names in the query, I presume by modifying your code slightly I could achieve this.


btw guys here is my code:


CODE

DECLARE @status CHAR(10)

SET @DateNow=convert(CHAR(10),getdate(),120)

SET @status='online'

SELECT REPLACE([ADEReport].[dbo].[User].[JID],'@bmwlds1mun.sei-it.net',' ')as Agent

,MIN(convert (varchar(10),DATEADD(Hour,2,ChangeTime),108)) as TimeLoggedIn

      FROM [ADEReport].[dbo].[PresenceChange]JOIN [ADEReport].[dbo].[User]

    ON [ADEReport].[dbo].[PresenceChange].[UID] = [ADEReport].[dbo].[User].[UID]

    AND CONVERT(CHAR(10),ChangeTime,120) = @DateNow

    AND PresenceStatus = @status

  group by JID

  order by JID asc";
 

RE: Insert space char into results

(OP)
Ok after a slight modification of your code it worked perfectly :), never thought of using string functions in SQL, it's actually quite practical.

thanx for you help.

CODE

(upper(left([ADEReport].[dbo].[User].[JID],1))+' '+upper(left(substring([ADEReport].[dbo].[User].[JID],2,len([ADEReport].[dbo].[User].[JID])-1),1))+ substring([ADEReport].[dbo].[User].[JID],3,len([ADEReport].[dbo].[User].[JID])-2

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close