SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Replace or Substring?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SSSQL2008R2
Starting Member

United Kingdom
3 Posts

Posted - 01/05/2013 :  19:08:21  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 01/06/2013 :  09:48:31  Show Profile  Reply with Quote
sounds like this

UPDATE table
SET Col = '2013' + Col

in case Col is of numeric type (int,decimal,numeric,flost etc) then use

UPDATE table
SET Col = '2013' + CAST(Col AS varchar(30))



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

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 01/07/2013 :  07:59:52  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Alternatively without changing the actual data, you can also append this when you SELECT data

SELECT col+'2013' FROM table WHERE ...

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SSSQL2008R2
Starting Member

United Kingdom
3 Posts

Posted - 01/07/2013 :  22:42:48  Show Profile  Reply with Quote
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!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/07/2013 :  23:28:56  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000