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)
 Select stmt - Help needed

Author  Topic 

misterraj
Yak Posting Veteran

94 Posts

Posted - 2007-07-17 : 02:47:18
HI all,
I have a table (eg) having two columns col1 and col2 having 100 rows/values.

i want to write a select statement, which when executed would result in Insert statements for the program, here in the case as tehre are 100 rows it should give 100 insert statements.

select 'Insert into table (' ??????????

any help would be appreciated.

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-07-17 : 03:14:00
Hi,

Plz do check with the following SQL

SELECT 'INSERT INTO <NEW TABLE> (col1 , col2) VALUES(' + CAST(col1 AS VARCHAR(4)) + ',''' +
CAST(RTRIM(col2) AS VARCHAR(10)) + ''')'
FROM <SOURCE TABLE>
Go to Top of Page

misterraj
Yak Posting Veteran

94 Posts

Posted - 2007-07-17 : 03:20:31
that worked nice aravind, thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-17 : 05:30:44
Also refer
http://vyaskn.tripod.com/code/generate_inserts.txt

Madhivanan

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

- Advertisement -