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)
 update query help

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-03-31 : 02:39:38
Dear all,

I need to update a single column with the below fashion.

I have a value in a column "C10 , Location_name is invalid. Cannot contain address"

Here i need to update/replace with "10-Error , Location_name is invalid. Cannot contain address"

Pls help me to have this get done.


Thanks,
Gangadhara MS
SQL Developer and DBA

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-31 : 08:07:44
It is not quite clear to me what the rule for updating based on the one example you have given. If the rule is, for example, "in every row where the column starts with a letter followed by two digits and a space, remove the letter and append '-Error' to the number", then that can be done like this:
update
YourTable
set
YourColumn = case when patindex('[A-Za-z][0-9][0-9] %',YourColumn) > 0 then
stuff(stuff(YourColumn,charindex(' ',YourColumn),1,'-Error '),1,1,'') else YourColumn end
If that is not what you are looking for can you describe the rule more precisely, similar to what I have done with my example rule?

Edit: I read my own "clear" description of the rule and realized that it was not clear at all. Hopefully fixed it.
Go to Top of Page
   

- Advertisement -