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
 General SQL Server Forums
 New to SQL Server Programming
 adding an 'A' to most of the data in the column

Author  Topic 

shaharidan
Starting Member

2 Posts

Posted - 2011-10-21 : 17:13:25
Microsoft SQL 2005

I have a table called Room.
The table has 3 columns.
1) OriginId
2) Room
3) RoomConv

I 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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-22 : 04:51:24
[code]
UPDATE t
SET t.Room=Room+'A'
FROM table t
WHERE t.Room NOT LIKE '%[A,B]'
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shaharidan
Starting Member

2 Posts

Posted - 2011-10-22 : 10:57:29
Thanks, worked great.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-22 : 11:40:49
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -