December 5, 2016 at 2:50 am
Hello,
I have two datetime columns, that I want to compare and get result just for one.
Something like this: SELECT IIF ( column1 > column2, column1, column2) AS Result;
How can I do it in my view?
Thanks.
December 5, 2016 at 2:52 am
use a case statement:
select case when column1 > column2 then column1 else column2 end as Result;
December 5, 2016 at 3:06 am
Thank you , btw. sometimes has column2 value = NULL and result is also NULL. I this case I want to put date from column1.
December 5, 2016 at 3:56 am
peter478 (12/5/2016)
Thank you , btw. sometimes has column2 value = NULL and result is also NULL. I this case I want to put date from column1.
CASE
WHEN column1 >= ISNULL(column2,Column1)
THEN column1
ELSE column2 END AS Result
This will handle that situation.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
December 5, 2016 at 9:38 am
Assuming that column1 cannot be null, then this will give the same results and should be slightly faster.
CASE
WHEN column2 > column1
THEN column2
ELSE column1 END AS Result
You have three conditions:
, and you want column1 returned under two of those conditions, so you want to test for the one condition where you're not returning column1.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply