|
Prev: how to strip specific email address from nvarchar field with m
Next: Using an SQL function as part of a view
From: mutasie on 2 Jul 2008 10:56 Hello, I would like to store multiple dynamic SQL in some meta table and use a cursor to read selected dynamic sql and execute to increase flexibility. Is this even possible? See code example below:... declare @csql nvarchar(4000) DECLARE c1 CURSOR READ_ONLY FOR SELECT sql FROM dbo.AH_Test_Meta OPEN c1 FETCH NEXT FROM c1 INTO @csql WHILE @@FETCH_STATUS = 0 BEGIN EXEC sp_executesql @csql FETCH NEXT FROM c1 INTO @csql END CLOSE c1 DEALLOCATE c1
From: Uri Dimant on 2 Jul 2008 11:05 You can execute it but permit me to ask WHY? DECLARE @v VARCHAR(50); SET @v = 'N' + '''' + 'select getdate()' + ''''; EXEC ('EXEC sp_executesql ' + @v); "mutasie" <mutasie(a)gmail.com> wrote in message news:59ee5325-93c1-49e4-88c5-89ddf21abf51(a)s21g2000prm.googlegroups.com... > Hello, > > I would like to store multiple dynamic SQL in some meta table and use > a cursor to read selected dynamic sql and execute to increase > flexibility. Is this even possible? See code example below:... > > > > declare @csql nvarchar(4000) > > DECLARE c1 CURSOR READ_ONLY > FOR > SELECT sql > FROM dbo.AH_Test_Meta > OPEN c1 > > FETCH NEXT FROM c1 > INTO @csql > > WHILE @@FETCH_STATUS = 0 > BEGIN > > EXEC sp_executesql @csql > > FETCH NEXT FROM c1 > INTO @csql > > END > CLOSE c1 > DEALLOCATE c1
From: TheSQLGuru on 2 Jul 2008 11:05 This can be done. I have several clients that have systems like this. -- Kevin G. Boles Indicium Resources, Inc. SQL Server MVP kgboles a earthlink dt net "mutasie" <mutasie(a)gmail.com> wrote in message news:59ee5325-93c1-49e4-88c5-89ddf21abf51(a)s21g2000prm.googlegroups.com... > Hello, > > I would like to store multiple dynamic SQL in some meta table and use > a cursor to read selected dynamic sql and execute to increase > flexibility. Is this even possible? See code example below:... > > > > declare @csql nvarchar(4000) > > DECLARE c1 CURSOR READ_ONLY > FOR > SELECT sql > FROM dbo.AH_Test_Meta > OPEN c1 > > FETCH NEXT FROM c1 > INTO @csql > > WHILE @@FETCH_STATUS = 0 > BEGIN > > EXEC sp_executesql @csql > > FETCH NEXT FROM c1 > INTO @csql > > END > CLOSE c1 > DEALLOCATE c1
From: --CELKO-- on 2 Jul 2008 11:17 The short answer is yes, you can. The right answer is why would you do that? Dynamic SQL is bad enough -- it tells us that you have no idea what you are doing until someone decides at run time. Then there is SQL Injection, poor performance, etc. Then you have decided to implement this bad idea with cursors, which are also a bad programming practice. I will not even comment on mixing data and meta-data in a schema.
From: Steve on 2 Jul 2008 11:20 Why wouldn't you just create a procedure out of it then? "mutasie" wrote: > Hello, > > I would like to store multiple dynamic SQL in some meta table and use > a cursor to read selected dynamic sql and execute to increase > flexibility. Is this even possible? See code example below:... > > > > declare @csql nvarchar(4000) > > DECLARE c1 CURSOR READ_ONLY > FOR > SELECT sql > FROM dbo.AH_Test_Meta > OPEN c1 > > FETCH NEXT FROM c1 > INTO @csql > > WHILE @@FETCH_STATUS = 0 > BEGIN > > EXEC sp_executesql @csql > > FETCH NEXT FROM c1 > INTO @csql > > END > CLOSE c1 > DEALLOCATE c1 >
|
Next
|
Last
Pages: 1 2 Prev: how to strip specific email address from nvarchar field with m Next: Using an SQL function as part of a view |