question

Don 1 1 avatar image
Don 1 1 asked

Character String Manipulation

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

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Squirrel 1 avatar image
Squirrel 1 answered

you have NULL value in Sortcode

try below to see the record where SortCode is null

select *            
from   TempTable            
where  SortCode is null            
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.