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 |
SSSQL2008R2
Starting Member
3 Posts |
Posted - 2013-01-05 : 19:08:21
|
Hi all,I have a column which I am trying to prefix every entry to have a prefix of 2013. How would I go about doing this? I dont know what syntax you would use so that sql knows to start at the beginning of the string? Thanks in advance! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-06 : 09:48:31
|
sounds like thisUPDATE tableSET Col = '2013' + Colin case Col is of numeric type (int,decimal,numeric,flost etc) then useUPDATE tableSET Col = '2013' + CAST(Col AS varchar(30)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-01-07 : 07:59:52
|
Alternatively without changing the actual data, you can also append this when you SELECT dataSELECT col+'2013' FROM table WHERE ...MadhivananFailing to plan is Planning to fail |
|
|
SSSQL2008R2
Starting Member
3 Posts |
Posted - 2013-01-07 : 22:42:48
|
Hi guys, I managed to get this in the end, I added column for 2013 then added the column for 2013 to the one i was trying to concat with.Thanks for the replys! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-07 : 23:28:56
|
quote: Originally posted by SSSQL2008R2 Hi guys, I managed to get this in the end, I added column for 2013 then added the column for 2013 to the one i was trying to concat with.Thanks for the replys!
why do you need a separate column for this? you could just concat it on the fly as shown.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|