June 28, 2002 at 9:40 am
Hi Folks,
I am attempting to translate the following access code into T-SQL as part of a large select query. Any assistance or code greatly appreciated...
IIf (Count(IIF([Stats_Data].[Code] < 5 and [Stats_Data].[Modify_date] >= #4/4/2002#, 1, Null))>0,1,Null) As Review
June 28, 2002 at 10:53 am
iif( condition, true, false)
translates to
if condition
begin
true statements
end
else
begin
false statements
end
Steve Jones
June 28, 2002 at 9:54 pm
Actually, IIf is an "Inline If", which is used within a Select statement, not a standalone "If". The T-SQL equivalent of IIf is the Case statement - the Searched form of it for this example. Lookup Case in BOL.
Jay
Jay Madren
June 29, 2002 at 5:39 am
I'd agree that the case statement is probably the cleanest translation. One way would be like this:
declare @test-2 int
set @test-2=1
select case when @test-2=1 then 'true' else 'false' end
Depending on what you're doing, the IsNull and NullIf can also be good replacements. Books Online shows you how to use them. If the logic is fairly complex, you could also create a user defined function (SQL2K only) that would do all the testing and just return the result.
Andy
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply