Home Forums SQL Server 2005 T-SQL (SS2K5) Need HELP with using IF or CASE in Where clause.. RE: Need HELP with using IF or CASE in Where clause..

  • Try this:

    DECLARE @period VARCHAR(10)

    SET @period = 'current'

    select * from t_rbt_data

    where

    dt >= '2014-01-01' and

    dt < '2014-04-01' -- this ensures you get all records within the specified time frame regardless of time

    AND toy_type = 'robot'

    AND (@period <> 'current' or (@period = 'current' and material = 'metal'))