SubQuery yielding blank results

M

Michelle

Hello all.

I'm trying to do a subquery that pulls the previous days information.
Here's how my table is set up...

DailyInfo table

Cusip
04375CU
04375EH
1F0626C
04375CU
04375EH
1F0626C

AsOfDate
11/3/2008
11/3/2008
11/3/2008
10/31/2008
10/31/2008
10/31/2008
10/30/2008
10/30/2008
10/30/2008

Exp
..123
..234
..345
..456
..567
..678
..789
..891
..912

Fac
..987
..987
..987
..654
..654
..654
..321
..321
..321

What I'm trying to do is set up a new variable facRet = Exp(from prev
day)*Fac(from prev day). For example for 11/3/08 the 3 cusips should show

facRet
..456*.654
..567*.654
..678*.654

facRet should populate for every date except the first date of the table
since there obviously isn't a previous date. I've been to Allen Browne's
site ( http://allenbrowne.com/subquery-01.html#AnotherRecord ) and have been
trying to use that code, but all it's yielding is a blank variable. Here's
the code I have thus far. (Please note that here I'm only trying to pull the
prev day's Exp variable. I haven't gotten so far as to do the simple
multiplication as shown above.) If anybody has an insight where I'm going
wrong I would really appreciate it.

SELECT DailyInfo.Cusip,
DailyInfo.AsOfDate,
DailyInfo.Exp,

(SELECT TOP 1 Dupe.Exp
FROM DailyInfo Dupe
WHERE Dupe.Cusip = DailyInfo.Cusip
AND Dupe.AS_OF_DATE < DailyInfo.AsOfDate
ORDER BY Dupe.AsOfDate DESC, Dupe.Cusip) AS PriorExp

FROM DailyInfo;

I'm pretty sure that the AsOfDate variable is a date and not a string also.
(Is it perhaps because Cusip is an alphanumeric variable?) Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top