Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Converting MS Access query to SQL Server

Author  Topic 

alanlambert
Starting Member

26 Posts

Posted - 2004-09-29 : 06:13:29
If trying to convert some Access queries into Transact SQL.

One of the queries is a crosstab, which I know I can implement using a CASE statement. However, two of the 'Row Heading' values include Immediate If statements:

sombudget: Sum(IIf([balcode] Like "P-BUD*",[full_value]))

sombesteed: Sum(IIf(([balcode]="werkelijk" Or [balcode]="Actual") And [el1]<'605',[full_value]))

How would I accomplish the same thing in T-SQL? Is it simply a case of using CASE again? I can understand how you could use CASE for the first of these statements, but how could you do it for the second where you are having to evaluate based on 2 different fields.

I'm really stumped on this so any help you can give would be greatly appreciated.

Many thanks,

Alan

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-29 : 06:19:01
this should help

Sum(IIf([balcode] Like "P-BUD*",[full_value])):
sum(case when [balcode] Like 'P-BUD%' then [full_value] end)

Sum(IIf(([balcode]="werkelijk" Or [balcode]="Actual") And [el1]<'605',[full_value])):
sum( case when ([balcode]="werkelijk" Or [balcode]="Actual") And [el1]<'605' then [full_value] end)

IMHO, you'll probably need an else in there...

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -