May 4, 2007 at 10:28 am
Hi
I need one help in TSQL. I have a column in table where all values are in below pattern:
‘HELLOXXXXXX” – XXX is subsequent string or blank
I need to keep the HELLO part in the original column and take the remaining part to another column of the same row. I think a cursor will be best for this. But I have the following doubts:
1. Is there a better way as table has about 5 Million rows and is under OLTP?
2. What is the way for to break HELLOXXXXXX into HELLO and XXXX… into two different variable?
Thanks in advance for your help.
Regards
Utsab Chattopadhyay
May 4, 2007 at 10:34 am
Do all say Hello? If so why not just drop Hello? as you will now need to repeat the same thing for all 5 million rows unnessarily if that is what all will say.
As for how
LEFT(ColName, 5) As HelloPart, RIGHT(ColName, LEN(ColName) - 5) As OtherPart
But be carefull if you have any items that are like this
'HELLOAAA '
the Right can mess up might be best to do
LEFT(ColName, 5) As HelloPart, RIGHT(RTrim(ColName), LEN(RTrim(ColName)) - 5) As OtherPart
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply