Monday, March 12, 2012

I am trying to convert a MS Access Query to a SQL query and I need help?

I am trying to convert a MS Access Query to a SQL query and I need help with some IIF Statements?

2 in particular that I've encountered problems with are:

Count(IIf([elphoursflag]=0 Or [elphoursflag]=2,IIf([envelopes].isitecode=[logsheets].isitecode,IIf([recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd([d],13,[dFirstPSYDate])),[zip]))))'AS wk2count,

AND

Format(Avg(IIf([elphoursflag]=0 Or [elphoursflag]=2,IIf([envelopes].isitecode=[logsheets].isitecode,IIf([recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd([d],13,[dFirstPSYDate])),[elphours])))),[0.0])AS wk2avg,

Any help that someone could offer would be greatly appreciated!
Thanks!After some more effort, I was able to get this working:
Count(case
when [elphoursflag]=0 Or [elphoursflag]=2 then
case
when [envelopes].isitecode=[logsheets].isitecode then
case
when [recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd([d],13,[dFirstPSYDate])) then
[zip]
end
end
end) AS wk2count,
Round(Avg(case
when [elphoursflag]=0 Or [elphoursflag]=2 then
case
when [envelopes].isitecode=[logsheets].isitecode then
case
when [recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd(day,13,[dFirstPSYDate])) then
elphours
end
end
end), 0.0) AS wk2avg,

Quote:

Originally Posted by newtechiebug

I am trying to convert a MS Access Query to a SQL query and I need help with some IIF Statements?

2 in particular that I've encountered problems with are:

Count(IIf([elphoursflag]=0 Or [elphoursflag]=2,IIf([envelopes].isitecode=[logsheets].isitecode,IIf([recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd([d],13,[dFirstPSYDate])),[zip]))))'AS wk2count,

AND

Format(Avg(IIf([elphoursflag]=0 Or [elphoursflag]=2,IIf([envelopes].isitecode=[logsheets].isitecode,IIf([recdate] Between DateAdd([d],7,[dFirstPSYDate]) And (DateAdd([d],13,[dFirstPSYDate])),[elphours])))),[0.0])AS wk2avg,

Any help that someone could offer would be greatly appreciated!
Thanks!

No comments:

Post a Comment