using =iif in query

  • Hey

    I got a problem, i need to fill a table with data - however I need a bunch of paramters which I can get to work - but the problem is I also want to choose 0 parameters or a "fake" parameter, that will then do another query, becuase the one with paramters will use a sql query with "where in (@partners)" and the other will just select all.

    And I cant just select all the avaiable paramters as some of the rows from the dataset havent set the id

    How can I fix this? Thanks

  • How about adding that fake parameter in your query

    If (@Parameter = 'Fake')

    Select

    ......

    Else

    Select

    ...

    where xyz = @Parameter

  • Thanks a bunch, it is nearly working now.

    However, I can execute the two queries in statement now, however when I select multiple paramters, I gets an error "query execution failed for dataset1......"

    But it works, if I select the "fake" parameter or a single parameter.

    The query looks like this:

    IF @partner = 0

    BEGIN

    SELECT

    thedata

    FROM

    thetable

    WHERE

    thedata = 3

    END

    ELSE

    SELECT

    thedata

    FROM

    thetable

    WHERE

    thedata = 3

    and partner in (@partner)

    END

    ELSE

    PS: The query is heavily simplified as to a lot of joins etc, but you get the point:)

  • I got it to work, by making a new parameter which could be evaluted on if all or just the where in ids should be listet - and it works:)

Viewing 4 posts - 1 through 3 (of 3 total)

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