AZV
02-04-2010, 08:13 AM
Hi,
I have stuck on this nested IIF case. Point is that I want to select records from 1 last working day skipping weekends and hollidays and starting calculating -2 days from entered [a] date.
I have one Bdaily table and Calendar table with marked days (Day=7 means it is non working day)
This is code that I set till now but I'm receiving an msg "At most one record can be returned by this subquery"
SELECT * INTO TEMP_3DAYS
FROM BDaily
WHERE DAY=(SELECT Date
FROM Calendar
WHERE Date=
IIf((Date=DateAdd('d',-2,[a]) And (Day<>7) ),Date,
(SELECT Date FROM Calendar as a where a.Date=IIf((a.Date=DateAdd('d',-3,[a]) And (a.Day<>7) ),a.Date,
(SELECT Date FROM Calendar as b where b.Date=IIf((b.Date=DateAdd('d',-4,[a]) And (b.Day<>7) ),b.Date,DateAdd('d',-1,[b.Date]))
)))));
I can't see why there is more dates results instead of one?
I have stuck on this nested IIF case. Point is that I want to select records from 1 last working day skipping weekends and hollidays and starting calculating -2 days from entered [a] date.
I have one Bdaily table and Calendar table with marked days (Day=7 means it is non working day)
This is code that I set till now but I'm receiving an msg "At most one record can be returned by this subquery"
SELECT * INTO TEMP_3DAYS
FROM BDaily
WHERE DAY=(SELECT Date
FROM Calendar
WHERE Date=
IIf((Date=DateAdd('d',-2,[a]) And (Day<>7) ),Date,
(SELECT Date FROM Calendar as a where a.Date=IIf((a.Date=DateAdd('d',-3,[a]) And (a.Day<>7) ),a.Date,
(SELECT Date FROM Calendar as b where b.Date=IIf((b.Date=DateAdd('d',-4,[a]) And (b.Day<>7) ),b.Date,DateAdd('d',-1,[b.Date]))
)))));
I can't see why there is more dates results instead of one?