Solved

pass where clause to stored procedure for cursor

Posted on 2004-10-31
303 Views
Last Modified: 2006-11-17
Is it possible?
something like that

DECLARE C  CURSOR FOR SELECT * FROM TABLE WHERE @WHERE_CLAUSE
0
Question by:kako
    1 Comment
     
    LVL 17

    Accepted Solution

    by:
    if you want to do something like this you need to use dynamic SQL

    declare @MySQL varchar(1000)
    set @MySQL = 'DECLARE C  CURSOR FOR SELECT * FROM TABLE WHERE ' + @WHERE_CLAUSE
    exec (@MySQL)

    just beware of the potential security risk here , particularly if @WHERE_CLAUSE is passed in as a parameter.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    I recently came across an interesting Question In EE (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/Q_27070749.html?cid=1135#a35876665) and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now