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 |
|
ganesh21
Starting Member
3 Posts |
Posted - 2008-07-30 : 17:28:25
|
| Hi everyone,this is the first time i am posting. if i am posting in the wrong section, please let me know.They question have is when i do an INSERT to have several columns data move into one column.An example:column Datastreet: 11 city: Testzip: 9999Results of Address: 11Test9999insert into location(Address, street, city, zip) values (@address, @street, @city, @zip) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-30 : 17:42:17
|
| You can concatenate data/columns/variables together with + sign.SELECT Column1+Column2+Column3...@var1+@var2+@var3 (make sure they are character columns as 11+22+33 will yield a different result)...Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
ganesh21
Starting Member
3 Posts |
Posted - 2008-07-30 : 20:45:28
|
| the data that are enter are not character. they are int & tinyint. if i did the var1+var2+var3 i will up get getting a total which i do not want. |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2008-07-31 : 04:57:23
|
| convert into character and then concantenate if @var1 is int then convert(varchar(20),@var1)+@var2+@var3 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-31 : 05:32:00
|
| And also check for nulls before concatenation just in case the columns are nullable. |
 |
|
|
ganesh21
Starting Member
3 Posts |
Posted - 2008-07-31 : 10:06:41
|
| Thank everyone for there help. |
 |
|
|
|
|
|