E
E
e1s2015-12-07 18:33:14
SQL Server
e1s, 2015-12-07 18:33:14

Why don't arithmetic operations work in case in ms sql?

I can't understand why datepart(ww, part_date) - 1 is not being subtracted in the following construction

select 
case  
when datepart(weekday, part_date) = 1 then datepart(ww, part_date) - 1 else datepart(ww, part_date) as part_week
end

The condition itself works, if instead of datepart(ww, part_date) - 1, just write 1, then everything is replaced. Tried cast and convert to int , still one is not subtracted from datepart(ww, part_date) value

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mc_marsel, 2015-12-07
@mc_marsel

Data types in the studio!

E
e1s, 2015-12-08
@e1s

-1 + datepart(ww, part_date) - this is how it works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question