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.
| Author |
Topic |
|
tchelcho
Starting Member
4 Posts |
Posted - 2009-04-07 : 13:11:00
|
| I need to UPDATE a column in a table to include a prefix.The prefix I need in front of each code is "LAB-"TABLE NAME = ServiceCODE | DESC10010 Complete Blood Count10020 Troponin10030 BMP10031 CMPI need it to look like:CODE | DESCLAB-10010 Complete Blood CountLAB-10020 TroponinLAB-10030 BMPLAB-10031 CMPHow would I write a statement that would take care of these. There are almost two thousand rows so I would hate doing it manually.Thanks for your assistance. |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-04-07 : 13:12:54
|
| You won't have to do it manually. Just look in BOL for UPDATE statement. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-07 : 13:14:07
|
| just useUPDATE Service SET CODE='LAB-'+CODEalso CODE should be of nonnumeric type for above |
 |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2009-04-08 : 05:27:07
|
| Don't forget to use CONVERT , as you will be ending up with a stringJack Vamvas--------------------http://www.ITjobfeed.com |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2009-04-08 : 05:43:53
|
quote: Originally posted by visakh16 just useUPDATE Service SET CODE='LAB-'+CODEalso CODE should be of nonnumeric type for above
but if there happens a null in code, will not be updatedso i think we have to addUPDATE Service SET CODE='LAB-' where CODE is nullok tanx... |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-04-08 : 07:43:44
|
That is not correct.It will update only records with codes as null.quote: Originally posted by soorajtnpki
quote: Originally posted by visakh16 just useUPDATE Service SET CODE='LAB-'+CODEalso CODE should be of nonnumeric type for above
but if there happens a null in code, will not be updatedso i think we have to addUPDATE Service SET CODE='LAB-' where CODE is nullok tanx...
|
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2009-04-08 : 08:13:39
|
| hi matty, I said u have to add/execute UPDATE Service SET CODE='LAB-' where CODE is null after executing query UPDATE Service SET CODE='LAB-'+CODEthen whole will be updated as required.ok tanx... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-10 : 06:32:57
|
quote: Originally posted by soorajtnpki
quote: Originally posted by visakh16 just useUPDATE Service SET CODE='LAB-'+CODEalso CODE should be of nonnumeric type for above
but if there happens a null in code, will not be updatedso i think we have to addUPDATE Service SET CODE='LAB-' where CODE is nullok tanx...
if CODE IS NULL then shouldnt it remain as NULL itself after updation? even in that case my solution will work as long as CONCAT NULL YIELDS NULL setting is on |
 |
|
|
|
|
|