This is a discussion on How to use Cursors that was built by Dynamic SQL within the Database Support forums, part of the Web Development category; This is one of the way to use cursors built by Dynamic SQL. CREATE PROCEDURE STP_DemoDynaCursor @Table SYSNAME, @Column SYSNAME, @...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| This is one of the way to use cursors built by Dynamic SQL. CREATE PROCEDURE STP_DemoDynaCursor @Table SYSNAME, @Column SYSNAME, @DynaCur CURSOR VARYING OUTPUT AS BEGIN DECLARE @Sql NVARCHAR(500) SELECT @Sql = 'SET @DynaCur = CURSOR STATIC FOR' +' SELECT '+ @Column +' FROM ' +@Table +'; OPEN @DynaCur;' EXEC SP_EXECUTESQL @Sql, N'@DynaCur CURSOR OUTPUT', @DynaCur OUTPUT END Code to access above Procedure: CREATE PROCEDURE STP_DemoDynaCurCall @APTable SYSNAME, @APColumn SYSNAME AS BEGIN DECLARE @CurResultSet CURSOR EXEC STP_DemoDynaCursor @Table = @APTable, @Column = @APColumn, @DynaCur = @CurResultSet OUTPUT FETCH NEXT FROM @CurResultSet; WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM @CurResultSet END CLOSE @CurResultSet DEALLOCATE @CurResultSet END Can anyone find some other script, Please post it... |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Static and Dynamic testing | vigneshgets | Software Testing | 0 | 01-15-2008 09:56 PM |
| How to create and use server side cursors in SQL Server? | oxygen | Database Support | 2 | 08-01-2007 08:54 AM |
| How to Perform SQL Server Row-by-Row Operations Without Cursors? | oxygen | Database Support | 1 | 07-30-2007 01:22 AM |
| Does the .NET Framework have in-built support for serialization? | anbuchezhians | VB.NET Programming | 1 | 07-27-2007 06:00 AM |
| Static IP & Dynamic IP | vadivelanvaidyanathan | Server Management | 0 | 07-15-2007 06:53 PM |