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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 On Insert- Insert Multipy columns into one column

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 Data
street: 11
city: Test
zip: 9999

Results of Address: 11Test9999

insert 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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page

ganesh21
Starting Member

3 Posts

Posted - 2008-07-31 : 10:06:41
Thank everyone for there help.
Go to Top of Page
   

- Advertisement -