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 |
BulletSponge
Starting Member
2 Posts |
Posted - 2007-05-01 : 12:49:44
|
I've got a Test Access database that has some parameter queriesfirst one is simple;***** QRY-1SELECT x, y, Min(z) AS NextDateFROM AWHERE z >=[@BaseDate]GROUP BY x, y***** QRY-2SELECT A.x, A.y, B.m B.n FROM (QRY-1 INNER JOIN B ON QRY-1.x= B.x) INNER JOIN A ON (QRY-1.x = A.x) AND (QRY-1.y = A.y) AND (QRY-1.NextDate = A.z)ORDER BY A.x, A.y---- OK, now in Access, when I open QRY-2, it asks for a @BaseDate, which is set, and it returns what I want...In SQL-Server, it doesn't work. You have any ideas why?Here's the SQL-Server crapCREATE PROCEDURE QRY-2(@BaseDate as smalldatetime)ASSELECT A.x, A.y, B.m, B.nFROM [QRY-1] INNER JOIN [B] ON [QRY-1].[x] = [B].[x]) INNER JOIN [A] ON ([QRY-1].[x] = [A].[x]) AND ([QRY-1].[y] = [A].[y]) AND ([QRY-1].[NextDate] = [A].[z])ORDER BY A.x, A.yGOLooks the same right? So it should work right?It gives me "Invalid object name 'QRY-1'." instead::EDIT::I found this which also describes my problem, but I'm trying to avoid a temporary table;http://www.thescripts.com/forum/thread494349.html |
|
mattyblah
Starting Member
49 Posts |
Posted - 2007-05-01 : 18:13:17
|
try this:SELECT A.x, A.y, B.m B.n FROM (SELECT x, y, Min(z) AS NextDateFROM AWHERE z >=[@BaseDate]GROUP BY x, y) qry_1INNER JOIN B ON QRY_1.x= B.xINNER JOIN A ON (QRY_1.x = A.x) AND (QRY_1.y = A.y) AND (QRY_1.NextDate = A.z)ORDER BY A.x, A.ylet me know how that works out. |
 |
|
BulletSponge
Starting Member
2 Posts |
Posted - 2007-05-01 : 21:17:17
|
That got it.I guess sometimes it doesn't pay to keep things clean |
 |
|
|
|
|
|
|