Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 character string manipulation

Author  Topic 

donchamp
Starting Member

9 Posts

Posted - 2010-07-03 : 20:44:43
I a table with the following data:

Sortcode Code Length
-------- ---- ------
abcd

I need to retrieve only the last character and update the code column with that character. I then need to update the length column with the length of the Sortcode column.
I executed the following code and the code transformation was successful but I got nulls in the length column. Kindly suggest how I can resolve this.

update TempTable set code = right(Sortcode,1)
where right(Sortcode,1) is not null
GO
SELECT leng = DATALENGTH(Sortcode), Sortcode
FROM TempTable
Update TempTable
set ID = leng

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-04 : 02:56:33
Try this:

Update TempTable Set Code = right(Sortcode,1), Length = Len(SortCode)
where Sortcode is not null


Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

donchamp
Starting Member

9 Posts

Posted - 2010-07-04 : 12:02:09
Thanks Bohra, I tried it and it worked perfectly.
Regards, Don
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-05 : 00:23:11
Glad to help
Go to Top of Page
   

- Advertisement -