Select that always returns one value

  • I have a query similar to:

    SELECT Column1 FROM Table1 WHERE Column2 IN(SELECT Column2 FROM Table2 WHERE Column3=@Value1) AND Colum4=@Value2

    What I want is the Subquery to always return one additional value.

    ie if the subquery returns 'item1', I want it to be 'item1', 'mystaticitem'

    Is it possible to construct a SELECT such that it will always append this static value to the result set?

    If not - any suggestions on how to accomplish this (other than first inserting the subquery into a temp table, adding my static value and then making doing a subquery select from the temp table)- which works, I'm just looking for a 'cleaner' alternative.

  • Just change your sample query to the following:

    SELECT Column1 FROM Table1 WHERE Column2 IN

    (SELECT Column2 FROM Table2 WHERE Column3=@Value1

    UNION SELECT 'mystaticitem'

    )

    AND Colum4=@Value2

  • Of course (slaps head)!

    Sometimes the forest gets in the way...

    Thanks for the quick reply.

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

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