Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    16

    Wink Unanswered: Dynamic delcare variables and dynamic building of where clause

    Hi

    I need to declare the variables dynamically
    the stored procedure will recieve an input parameter which will decide how many variables need to be declared

    for eg
    If the stored procedure receives the input param as 3
    then i need to declare 3 variables
    if it says 6 then i need to declare 6 variables

    First thing --can any one let me know how can i declare the variable dynamically based on the input parameter passed.

    Second thing is then how can these dynamically created variables be passed to the where clause
    The need for this is

    i have a sp which will retrieve the data from the table
    the input paramter is going to be a string which has the values delimited with a comma. The string will look like as follows
    "'AA','CC','DD','AAA'"

    I have to retrieve the data from the table for the values passed in the string so the sql statement should be build up as

    The in clause will should be created dynamically based on the input parameter string

    select * from cdv
    where cdv_type in ('AA','CC','DD','AAA')

    in order to build the in clause i need to declare the variables dynamically

    or is there any way i can build the in clause dynamically
    Regards
    Shalu

  2. #2
    Join Date
    Nov 2002
    Posts
    207
    Can you give an example, like if I pass 3 as variable what will be defined in variables and how those variables will be used in the SQL. You can do dynamic SQL to do most of the stuff, but declaring dynamic variables... I need more input.

  3. #3
    Join Date
    Jul 2003
    Posts
    16
    Fo eg. if i pass 3 variable

    the variables can be declared as
    parm1
    parm2
    parm3
    Regards
    Shalu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •