T-SQL: CASE within WHERE

1

I have the following WHERE where I have to put a clause CASE to do a search depending on the name of the day and it gives me an error in = that is within THEN :

Declare @dia date = DATENAME(dw,GETDATE())--aqui obtengo el nombre del dia
        Select @Var = COUNT (tc.fecha)
                    FROM tcambio tc
                    INNER JOIN tmoneda tm 
                    ON tc.cod_moneda = tm.cod_moneda
                    WHERE @dia = CASE   WHEN @dia = 'Viernes' THEN tc.Fecha = convert(datetime,(GETDATE()+3)) 
    
asked by lanshare 02.08.2017 в 17:07
source

1 answer

0

I solved it with the help of @Lamak and it's like this:

Select @Var = COUNT (tc.fecha)
FROM dbo.tcambio tc 
INNER JOIN dbo.tmoneda tm 
    ON tc.cod_moneda = tm.cod_moneda 
WHERE tc.Fecha = CASE
        WHEN @dia = 'Viernes' or @dia = 'Friday' THEN 
            CONVERT(smalldatetime, GETDATE()+3) 
        WHEN @dia = 'Sábado' or @dia = 'Saturday' THEN 
            CONVERT(smalldatetime, GETDATE()+2) 
        WHEN @dia = 'Domingo' or @dia = 'Sunday' or @dia = 'Feriado' or @dia = 'Holiday' THEN 
            CONVERT(smalldatetime, GETDATE()+1)
        END
    
answered by 03.08.2017 в 14:58