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.
| 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 helpSum(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 |
 |
|
|
|
|
|