• lanky_doodle - Wednesday, February 28, 2018 8:16 AM

    Hello,

    I'm doing this:


    ...
    union
    select  'EVY', 'Everyone', ...
    from  ...
    where  ... and @Grouping = 'false'

    That @Grouping = false still returns the row if the value is true. I've worked out because I'm using constant values - 'EVY', 'Everyone' - instead of column values. If I change to column values it works as expected.

    How can I use constant values this way?

    Thanks

    What exactly are you trying to do, way too much of that code is redacted to be useful.  But in general UNION does an implicit DISTINCT on the entire result set so if you have a bunch of selects in the union that all return the same constant result set if if any of them return anything you'll get a single row back with that constant result. 

    SELECT * FROM (VALUES ('Hello'), ('Hello')) TESTY(COL_ONE)
    UNION
    SELECT 'Hello'