IT Community - Software Programming, Web Development and Technical Support

How to use Cursors that was built by Dynamic SQL

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, @...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-12-2008, 07:03 AM
vadivelanshanmugam vadivelanshanmugam is offline
D-Web Trainee
 
Join Date: Jan 2008
Posts: 41
vadivelanshanmugam is on a distinguished road
Default How to use Cursors that was built by Dynamic SQL

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 04:25 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0