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 |
|
shaharidan
Starting Member
2 Posts |
Posted - 2011-10-21 : 17:13:25
|
| Microsoft SQL 2005I have a table called Room.The table has 3 columns.1) OriginId2) Room3) RoomConvI would like to add the letter 'A' to anything in the column Room that doesn't allready have a letter 'A' or 'B' in the Room.So Room '1000' would become room '1000A'Room '2000A' would stay Room '2000A'Room '3000-B' would stay Room '3000-B'Any help would be appreciated I have some experience with Cache SQL, but nothing I've tried is working in microsoft.Thanks,Mike |
|
|
DBAPBFL
Starting Member
11 Posts |
Posted - 2011-10-21 : 17:48:17
|
| declare @room varchar(100)='1000'select case when (charindex('A',@room)>0 or charindex('B',@room)>0) then @room else @room+'A' end |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-22 : 04:51:24
|
| [code]UPDATE tSET t.Room=Room+'A'FROM table tWHERE t.Room NOT LIKE '%[A,B]'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
shaharidan
Starting Member
2 Posts |
Posted - 2011-10-22 : 10:57:29
|
| Thanks, worked great. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-22 : 11:40:49
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|