T-SQL Question - TechRepublic
Question
July 3, 2009 at 01:39 PM
slayer_

T-SQL Question

by slayer_ . Updated 17 years ago

My problem is simple. The first character of a piece of data in a column may be invalid. I need a script to fix it. Preferably not using a stored procedure.

My first idea was this
Update Service10
Set LN_SmString2 = (‘M’ + RIGHT((Select LN_SmString2 From Service10),Len(Select LN_SmString2 From Service10) – 1)))
Where LEFT(LN_SmString2,1) <> ‘M’ or LEFT(LN_SmString2,1) <> ‘S’ or LEFT(LN_SmString2,1) <> ‘D’

I’ve bolded the specific problem, how do I tell it which row to grab the data, the select and the update need to be looking at the same row for this to work.

If there is an easy solution to this, I’d like to know.

Otherwise, my solution would be using a variable and a curser. That should work fine EXCEPT I only know how to use variables and cursors in stored procs. I again, don’t want a stored proc, just a single use script. Online help is not very helpful for some reason with this issue, so help would be appreciated.

The jyst of this script is this.

If the first characters is not M, S, or D, then make it M. All characters after that must remain the same. It is a 30 character CHAR and each character represents something to the system.

This discussion is locked

All Comments