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)
 need to generate a script

Author  Topic 

jayanth_jyothi
Starting Member

11 Posts

Posted - 2007-08-16 : 19:16:43
Hi
I need to solve one problem
there is one table say TableA with columns orgid int
suppose say some 1000 records are there
for each record based on the value of orgid
i have to generate a script like this

if not exists (select * from TableB where orgid=each record value) then insert into tableb (orgid) else print already exists
like this i have to generate a script

can u please give me idea how to do this in dynamic sql

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-16 : 19:27:04
Why the use of DYNAMIC SQL?
INSERT		TableB
(
OrgID
)
SELECT a.OrgID
FROM TableA AS a
LEFT JOIN TableB AS b ON b.OrgID = a.OrgID
WHERE b.OrgID IS NULL



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jayanth_jyothi
Starting Member

11 Posts

Posted - 2007-08-16 : 19:40:11
see i have to generate sql script for this
not sql query
see tableA there is 10,11,12 ids
based on these values

i have to generate three sql statments as scripts
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-17 : 02:20:54
http://vyaskn.tripod.com/code/generate_inserts.txt

Madhivanan

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

- Advertisement -