Quick question on how to judge if an integer equal to any integer

  • I have a where clause, I want to say if @user-id <> 0 then @user-id could be any integer.

    Something like: u2.id like case when @user-id <> 0 then @user-id else '%%' end

    but this works only to varchar compare.

    How do I say that in my query?

    Thanks.

  • Will this be OK?

    .. where @user-id = 0 or u2.id = @user-id

    Regards

    Piotr

    ...and your only reply is slàinte mhath

  • thanks. it won't work.

    The records are all associated with a UserID, all non 0 value.

    When the input parameter is 0, all records should be pulled out.

    When the input parameter is not 0, only the specific UserID records should be pulled out.

  • halifaxdal (3/8/2010)


    thanks. it won't work.

    The records are all associated with a UserID, all non 0 value.

    When the input parameter is 0, all records should be pulled out.

    When the input parameter is not 0, only the specific UserID records should be pulled out.

    try what Piotr gave you; that will give you all users if the @userid=0

    OR one specific user if it is not.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (3/8/2010)


    halifaxdal (3/8/2010)


    thanks. it won't work.

    The records are all associated with a UserID, all non 0 value.

    When the input parameter is 0, all records should be pulled out.

    When the input parameter is not 0, only the specific UserID records should be pulled out.

    try what Piotr gave you; that will give you all users if the @userid=0

    OR one specific user if it is not.

    try it! you'll like it.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • try it! you'll like it.

    Sorry guys, I was hoping to see some case when query and didn't even try it, my apologies for this, it does work.

    Thank you lots.

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

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