SQL CASE Statement (keeping the CASE statement within the WHERE clause)?

Select * from Ext_Meeting_Status where Ext_Meeting_Status_ID = CASE WHEN (GETDATE() = '2010-12-13 10:02:31.560') THEN (2) ELSE (4) END I believe this should work One more note : Comparing current date to the exact millisecond level might not work as the query may not get executed at that time You may try something like this Select getdate(), * from #Temp Where ID = Case when getdate() between '2010-12-13 05:21:08.240' and '2010-12-13 05:22:08.240' Then 1 Else 2 End.

Select * from Ext_Meeting_Status where Ext_Meeting_Status_ID = CASE WHEN (GETDATE() = '2010-12-13 10:02:31.560') THEN (2) ELSE (4) END I believe this should work.. One more note : Comparing current date to the exact millisecond level might not work as the query may not get executed at that time... You may try something like this. Select getdate(), * from #Temp Where ID = Case when getdate() between '2010-12-13 05:21:08.240' and '2010-12-13 05:22:08.240' Then 1 Else 2 End.

Thanks mate - this sounds great – user532104 Dec 13 '10 at 10:22.

I don't think it's possible. You may want to try to put it all into a sub-select and use the CASE there.

SQL Server allows for only 10 levels of nesting in CASE expressions. The CASE expression cannot be used to control the flow of execution of Transact-SQL statements, statement blocks, user-defined functions, and stored procedures. For a list of control-of-flow methods, see Control-of-Flow Language (Transact-SQL).

The CASE statement evaluates its conditions sequentially and stops with the first condition whose condition is satisfied. In some situations, an expression is evaluated before a CASE statement receives the results of the expression as its input. Errors in evaluating these expressions are possible.

Aggregate expressions that appear in WHEN arguments to a CASE statement are evaluated first, then provided to the CASE statement. For example, the following query produces a divide by zero error when producing the value of the MAX aggregate. This occurs prior to evaluating the CASE expression.

You should only depend on order of evaluation of the WHEN conditions for scalar expressions (including non-correlated sub-queries that return scalars), not for aggregate expressions.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions