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 2000 Forums
 Transact-SQL (2000)
 Generating Insert Scripts

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2006-05-15 : 15:42:23
Guys,

I have table populated with data like

id name
_____________
1 john
2 doe

I have 40 rows I want to generate insert script for each of the row.

Can you guys tell me how to go about doing the same

Thanks

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-15 : 15:55:36
Where do u have ur 40 rows ?


Srinika
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-05-15 : 15:56:42
There are many ways... here is one:

http://vyaskn.tripod.com/code/generate_inserts.txt




Nathan Skerl
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-05-16 : 12:11:25
If you just want something very basic, you can just do this (of course)...

--data
declare @t table (id int, name varchar(10))
insert @t
select 1, 'john'
union all select 2, 'doe'

--calculation
select 'insert @t (id, name) values (' + cast(id as varchar(10)) + ', ''' + replace(name, '''', '''''') + ''')' from @t


(Assuming the answer to the question Srinika asked is that it's in the table you were talking about)

Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-05-16 : 13:11:02
Try this out... I think its on topic

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53420

Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page
   

- Advertisement -