passing multiple parameters to a stored proc

  • Hi Bob

    Very nice solution with the string-bitmap! 😉

    @ J-F

    Nice approach over an external file!

    My bad, I did not use that for a long time, it got me saying stupid stuff again![/b]

    There is nothing stupid you said.

    Greets

    Flo

  • Florian Reischl (4/2/2009)


    David,

    What about this:

    SELECT *

    FROM mytab

    WHERE col1 = ISNULL(@col1, col1)

    AND col2 = ISNULL(@col2, col2)

    AND col3 = ISNULL(@col3, col3)

    AND col4 = ISNULL(@col4, col4)

    AND col5 = ISNULL(@col5, col5)

    It's a little less than one million lines.

    Greets

    Flo

    Flo.

    This is not going to work correctly if the fields have NULLs.

    Regardless of the ANSI_NULLS settings. Any rows with NULLs on searched columns will be skipped.

    So if you have NULLable fields it is better to use syntax proposed by John

    EDIT

    Added John's code

    select*

    fromTable_1

    where (@select_1 is null or col_1 = @select_1)

    and (@select_2 is null or col_2 = @select_2)

    and (@select_3 is null or col_3 = @select_3)

    and (@select_4 is null or col_4 = @select_4)

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

  • JacekO (4/3/2009)


    Florian Reischl (4/2/2009)


    David,

    What about this:

    SELECT *

    FROM mytab

    WHERE col1 = ISNULL(@col1, col1)

    AND col2 = ISNULL(@col2, col2)

    AND col3 = ISNULL(@col3, col3)

    AND col4 = ISNULL(@col4, col4)

    AND col5 = ISNULL(@col5, col5)

    Flo.

    This is not going to work correctly if the fields have NULLs.

    Regardless of the ANSI_NULLS settings. Any rows with NULLs on searched columns will be skipped.

    So if you have NULLable fields it is better to use syntax proposed by John

    Thanks for correction! You are right!

    Greets

    Flo

  • No problem.

    Been there, got burnt... 😉

    The biggest surprise was that this is ANSI_NULLs independent. Regardless how you have this option set. ON or OFF the NULLs are not equal. I guess ISNULL must be doing something internally...

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

Viewing 4 posts - 16 through 18 (of 18 total)

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