Posted: Tue Jan 21, 2003 12:05 am Post subject: Shuffle the contents of a column
Hi all,
I have a db2 column defined as character of 50 and it contains the lastname followed a comma and the firstname.Now my requirement is to shuffle the contents of the column to be firstname and a comma and lastname
Joined: 26 Nov 2002 Posts: 12359 Topics: 75 Location: San Jose
Posted: Tue Jan 21, 2003 6:26 am Post subject:
Cj,
The following sql will give you the results.I have used the scalar function POSSTR to find the position of the comma and then use the SUBSTR scalar function to move the contents. I also used the STRIP scalar function to remove any trailing spaces. You can remove it if don't require the strip of the blanks
Code:
SELECT STRIP(SUBSTR(COLUMN_NAME,(POSSTR(COLUMN_NAME,',')+1),50))
CONCAT ',' CONCAT
STRIP(SUBSTR(COLUMN_NAME,1,(POSSTR(COLUMN_NAME,',')-1)))
FROM TABLENAME
;
check the following links for the scalar functions
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum