Results 1 to 2 of 2

Thread: How to use parameter in "Where ...IN..." clause.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    How to use parameter in "Where ...IN..." clause.

    How can i use parameter in "Where...IN... Clause" ?

    Consider this:

    Select ID from tb1 where ID IN (1,5,7,9)

    I want to use the part '1,5,7,9' as a parameter, but I dont know how. I tried to use this 'Select ID from tb2 where ID IN (?) ' in Data Adapter Configuration Wizard but i get the following error:

    "OleDbCommand.Prepare method requires parameters of type '14' have an explicitly set Precision and Scale."

    Any Idea?

  2. #2
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    You could pass the ID's in as a varchar parameter. In the database you could then split the value using a delimiter and convert that value to an int. Then build your query. This is my stripped down version in SQL Server to give you an idea.

    CREATE PROCEDURE Prop_UpdatePropManager(
    @Reg_Array Varchar(2000)
    ) AS

    BEGIN
    SELECT @nLen = Len(@Reg_Array)
    SELECT @nCnt = 1
    WHILE (@nCnt <= @nLen) BEGIN
    SELECT @sTmp = SUBSTRING(@Reg_Array,@nCnt,1)
    IF @sTmp = '|' BEGIN
    **** CODE HERE TO CONVERT TO ********
    CONVERT(Int,@sitem) etc etc
    END ELSE BEGIN
    SELECT @sItem = @sItem + @sTmp
    END
    SELECT @nCnt = @nCnt + 1
    END
    END
    Wind and waves resolves all problems.

Posting Permissions

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



Click Here to Expand Forum to Full Width