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
 Merging columns and adding text

Author  Topic 

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2010-10-02 : 10:32:01
Hi

I'd like to take two table columns and merge them with some text to create a new column in a view. I know the following is wrong, but it might help illustrate what I'd like to achieve:

select [competitionType] & ": in" [competitionLocation] as competitionInfo
from table competitions

Thanks for any help
Richard

Richard Law

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-02 : 10:34:42
select [competitionType] + ': in' + [competitionLocation] as competitionInfo
from table competitions

Note this will not work properly if there are null values in the columns.
Then you have to use isnull() or coalesce().


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-02 : 10:35:46
And if a column that you want to concatenate is a numeric datatype then you have to convert it to varchar.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2010-10-02 : 10:38:51
quote:
Originally posted by webfred

And if a column that you want to concatenate is a numeric datatype then you have to convert it to varchar.


No, you're never too old to Yak'n'Roll if you're too young to die.



Perfect. Many thanks

Richard Law
Go to Top of Page
   

- Advertisement -