Why is this not working?

  • declare @recipe table (recipeID numeric(18,0) NOT NULL)

    insert into @recipe(recipeID) values('4')

    insert into @recipe(recipeID) values('5')

    insert into @recipe(recipeID) values('6')

    insert into @recipe(recipeID) values('7')

    Declare @sql VarChar(1000)

    select sql = '''2'''

    DELETE from @recipe where recipeID in Exec (@SQL)

    many thanks

  • Well, there's a number of things I'd do differently...

    On the INSERT statements, you're not inserting string values so you don't need to encapsulate them in single-quotes.

    When you declare @sql, why are you making it varchar data if you're just going to store a numeric value in it to compare against other numeric values?

    Finally you shouldn't use the "in exec (@sql)". Perhaps if you could show a little more about what you're trying to do?

  • Exactly what you are trying to do ?

     

  • Dunno if this is what you are looking for... and I haven't tested it 'cause I'm on vacation with no access to SQL...

    declare @recipe table (recipeID numeric(18,0) NOT NULL)

    insert into @recipe(recipeID) values(1)

    insert into @recipe(recipeID) values(2)

    insert into @recipe(recipeID) values(3)

    insert into @recipe(recipeID) values(4)

    insert into @recipe(recipeID) values(5)

    insert into @recipe(recipeID) values(6)

    insert into @recipe(recipeID) values(7)

    Declare @ThingToDelete numeric(18,0)

    select @ThingToDelete = 2

    DELETE from @recipe where recipeID = @ThingToDelete

    I also think that Numeric(18,0) is real overkill, here... you might want to just try INT which goes to (approx) 2 Billion.

    If you are trying to delete multiple recipies based on a CSV list you're passing in, let us know 'cause that's a lot different...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Anyway it's good to learn some basics about syntax of the language before you try to use it.

    _____________
    Code for TallyGenerator

  • #1 problem:

    select sql = '''2'''

    You are trying to make your variable become '''2''', but that's not a variable. It's missing the @ symbol.

    select @sql = '''2'''

    -SQLBill

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply