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
 Data INsert

Author  Topic 

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-18 : 04:01:00
Hi Experts,
How can i insert data into a table from another table.The new table have different column name and in some coulmns i have to insert a default value.Please help

TIA

RKNAIR

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-18 : 04:12:43
INSERT INTO DestnTable(col1,col2,col3,col4,..)
SELECT MatchCol1,DEFAULT,MatchCol2,constvalue
FROM SrcTable

here 1 & 3rd fields take data from two fields of SrcTable while second field takes default value. 4th field has constant value
Go to Top of Page

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-18 : 04:21:01
Thanks alot visakh

RKNAIR
Go to Top of Page

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-18 : 05:15:51
hi,
I am facing another problem that i have N and Q as values in a column in old table and i want N as 1 and Q as 0 in the new table.What i have to do???

RKNAIR
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-18 : 05:22:43
Ex

INSERT INTO DestnTable(col1,col2,col3,col4,..)
SELECT MatchCol1,DEFAULT,MatchCol2,case when constvalue='N' then 1 when constvalue='Q' then 0 else constvalue end
FROM SrcTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-18 : 06:25:27
Thanks .........

RKNAIR
Go to Top of Page

ratheeshknair
Posting Yak Master

129 Posts

Posted - 2008-08-19 : 04:03:51
Hi ,
How can i insert three column values together in a single column and i need a space of char(13) in between each column value.


TIA

RKNAIR
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-19 : 04:10:14
quote:
Originally posted by ratheeshknair

Hi ,
How can i insert three column values together in a single column and i need a space of char(13) in between each column value.


TIA

RKNAIR


coalesce(col1,'')+char(13)+coalesce(col2,'')+char(13)+coalesce(col3,'')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-19 : 04:11:24
quote:
Originally posted by ratheeshknair

Hi ,
How can i insert three column values together in a single column and i need a space of char(13) in between each column value.


TIA

RKNAIR


have you tried this yourself before asking? If yes, can we see what you tried? if not, use books online look for INSERT satement for assistance, try it and post if you face any problem.
Go to Top of Page
   

- Advertisement -