Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Posts
    25

    Unanswered: stored procedure string question

    hello,

    i have a varchar variable called @categories. it's value is 1,2,3. it is actually integer values delimited by commas. i would like to run a cursor using this variable, such as:

    DECLARE curC CURSOR FOR
    (SELECT dCT.category_id, tI.productIndex FROM type_index tI INNER JOIN defaultCategory_Table dCT ON tI.productType = dCT.category_value
    WHERE dCT.category_parent IS NULL AND tI.productIndex IN (@categories))

    BUT obviously this doesn't work, i get a 'Syntax error converting the varchar value '1,2,3' to a column of data type int.'

    does anyone have any other ideas of how to do this rather easily?

    thanks.

  2. #2
    Join Date
    Mar 2003
    Location
    France
    Posts
    21
    What I suggest will work but it is nasty:

    declare @sql varchar(500)

    set @sql = 'DECLARE curC CURSOR FOR
    (SELECT dCT.category_id, tI.productIndex FROM type_index tI INNER JOIN defaultCategory_Table dCT ON tI.productType = dCT.category_value
    WHERE dCT.category_parent IS NULL AND tI.productIndex IN ('+@categories+'))'

    exec(@sql)

Posting Permissions

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