How to pass BIGINT data type values to IN CLAUSE in sql server 2008?

  • Hi,

    I have a below query-->

    declare @Rid bigint

    set @Rid =106,108;

    UPDATE Cust

    SET Cust.IsVal= 1

    FROM Cust

    INNER JOIN CustRid

    ON Cust.PlRid= CustRid.Id

    WHERE Cust.PId IN (@Rid)

    Here my Cust.PId is Bigint type and it will not allow me to pass values.

    How I pass @Rid to IN Clause when my Cust.PId is Bigint.

    Please suggest any approach!!!

  • This

    declare @Rid bigint

    set @Rid =106,108;

    generates an error, because bigint datatype holds a single bigint, not a list of them. If @Rid was a character type then you would be able to construct what looks like a list, like this:

    declare @Rid VARCHAR(100)

    set @Rid = '106,108';

    But it isn't, it's a single value. The list for an IN looks like this:

    IN (106,108) for BIGINT

    IN ('106','108') for character type

    There are numerous ways of dealing with this issue. Where does @Rid get populated? Is it, say, a parameter passed into a stored procedure? If so, you could split out the elements of the string into a proper table.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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