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)
 Dynamic DDL

Author  Topic 

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-02-02 : 18:42:58
hiya

I have a bunch of statements like

ALTER TABLE [LC2IEDM].[dbo].[ABS_POINT] WITH NOCHECK ADD PRIMARY KEY CLUSTERED ([abs_point_id]) ON [PRIMARY]


stored in a temp table called #alter


--now loop through and run sql statements
declare @runsql nvarchar(2000)

while exists (select sql from #alter)
begin
select top 1 @runsql = sql from #alter
exec (@statement)
delete from #alter where sql = @runsql
end


The code runs, reports no errors, says that all was completed OK, but no primary keys are added. If I change the exec to a select and then manually run each statement in QA - the code works.

Any ideas?

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"

nr
SQLTeam MVY

12543 Posts

Posted - 2003-02-02 : 18:56:18
try
exec (@runsql)

instead of
exec (@statement)

Apart from that it should work.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-02-02 : 18:58:34
er....um....ok

DOH!

Thanks nigel

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -