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 |
|
macca
Posting Yak Master
146 Posts |
Posted - 2008-11-10 : 06:49:43
|
| I am selecting 2 columns and want to combine them into one, here is the sql I am using:select (p.code AND p.user) AS landfrom pI keep getting the error "Incorrect syntax near the keyword 'AND'".Anyone any ideas.Thanks |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2008-11-10 : 06:54:04
|
| IF both columns are of strings thenSELECT p.code +''+p.user AS land FROM pelseSELECT CAST (p.code AS varchar(max)) +''+ CAST (p.user AS varchar(max)) AS land FROM p |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 06:56:36
|
| [code]SELECT COALESCE(p.code,'')+COALESCE(p.user,'') AS land FROM p[/code]if columns are nullable |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-10 : 08:21:50
|
| You may need to convert the datatype if they are of different datatypesMadhivananFailing to plan is Planning to fail |
 |
|
|
macca
Posting Yak Master
146 Posts |
Posted - 2008-11-11 : 04:52:27
|
| Thanks for your replies guys.I got that sorted. |
 |
|
|
|
|
|