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 |
|
jcb267
Constraint Violating Yak Guru
291 Posts |
Posted - 2009-01-20 : 15:32:02
|
| I am trying to run a query that will concatenate fields from a table in my database. I know how to get it to work in excel but cannot figure it out in SQL - I am using SQL 2005. Can anyone help me? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-01-20 : 15:38:13
|
| Hello;Here is a simple example of concatenation. You simply need to use the + operator.Assume you have a TABLE A with two columns called region_name and store_name... For this example there is only 1 entry as shown TABLE Aregion_name store_nameeastern bostonSELECT region_name + ' ' + store_name FROM TABLE AResult: easternbostonr&r |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-21 : 08:47:54
|
| make sure you convert NULL values to '' before concatenation using COALESCE() or ISNULL() just in case any of fields involved are nullable, otherwise concatenation will yield you only NULL if you've CONCAT NULLS YIELDS NULL setting ON. |
 |
|
|
|
|
|