• gbritton1 (5/7/2014)


    Sean Lange (5/7/2014)


    gbritton1 (5/7/2014)


    Sean Lange (5/7/2014)


    How about this?

    SELECT [Columns]

    FROM Test1 T1

    INNER JOIN Test2 T2 ON T1.ID = T2.ID

    WHERE CASE @p_flag

    WHEN 1 THEN moveFlag = 26

    ELSE moveFlag > 26 OR moveFlag < 26

    END

    how did you make this work? I copied and pasted this into SSMS, set up test tables but it won't parse. I get:

    Msg 102, Level 15, State 1, Line 3

    Incorrect syntax near '='.

    Ahh you are correct. It will not work as posted. This is some fallout from not having ddl and sample data to work with.

    This should work...of course it is untested for the same reason I didn't test my previous post.

    WHERE (@p_flag = 1 AND moveFlag = 26)

    OR (@p_flag <> 1 --if this is a bit I would use = 0 instead of <> 1

    AND moveFlag > 26 OR moveFlag < 26)

    This is similar to a catch-all type of query. Gail has an excellent article about that type of query here. http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]

    ...might want parens arount that inner OR condition, I spose

    Only if we want it to be correct. 😉 Good catch!!!

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/