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)
 Conditional update

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2007-09-03 : 15:22:02
I have a field category, I need to go through every row and if category doesn't start with : then add the : to the front.

If I was doing this in VB it would look something like this

If category.startswith(":") then
' Do nothing
Else
category = ":" + category
End If

Can I do this with an sql statement?

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-03 : 15:26:01
UPDATE Table1
SET Col1 = ':' + Col1
WHERE Col1 NOT LIKE ':%'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -