If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Is there something wrong with my SQL?
I'm trying to run a make table bringing the ID, InvNo & PONo fields from
T09_DupInvs1 table, and I want to rank the PONo field (preferably in order by ID [autonumber]). The result of the SQL below is the ID, PONo and Rank fields, but no InvNo. And the rank is 1 all the way down its field. What am I doing wrong? I'm very new to SQL. THANKS!!!! SELECT Q.ID, Q.InvNo, Q.PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; -- GD |
#2
|
|||
|
|||
Is there something wrong with my SQL?
SELECT Q.ID
, Q.InvNo , Q.PONo , You are missing this comma in the posted SQL (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; Do you want to start over at 1 for each InvNo and POno combination? That is what you seem to be doing with the above query. If you want one sequence of numbers for all the records, then (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[ID] Q.[ID]) If you want the sequence to restart with each PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) If you want the sequnce to restart with each InvNo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[ID] Q.[ID]) John Spencer Access MVP 2002-2005, 2007-2009 The Hilltop Institute University of Maryland Baltimore County GD wrote: I'm trying to run a make table bringing the ID, InvNo & PONo fields from T09_DupInvs1 table, and I want to rank the PONo field (preferably in order by ID [autonumber]). The result of the SQL below is the ID, PONo and Rank fields, but no InvNo. And the rank is 1 all the way down its field. What am I doing wrong? I'm very new to SQL. THANKS!!!! SELECT Q.ID, Q.InvNo, Q.PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; |
#3
|
|||
|
|||
Is there something wrong with my SQL?
Thanks, John!! That solved the ranking problem. But why wouldn't it be
including the InvNo field as a result? -- GD "John Spencer" wrote: SELECT Q.ID , Q.InvNo , Q.PONo , You are missing this comma in the posted SQL (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; Do you want to start over at 1 for each InvNo and POno combination? That is what you seem to be doing with the above query. If you want one sequence of numbers for all the records, then (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[ID] Q.[ID]) If you want the sequence to restart with each PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) If you want the sequnce to restart with each InvNo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[ID] Q.[ID]) John Spencer Access MVP 2002-2005, 2007-2009 The Hilltop Institute University of Maryland Baltimore County GD wrote: I'm trying to run a make table bringing the ID, InvNo & PONo fields from T09_DupInvs1 table, and I want to rank the PONo field (preferably in order by ID [autonumber]). The result of the SQL below is the ID, PONo and Rank fields, but no InvNo. And the rank is 1 all the way down its field. What am I doing wrong? I'm very new to SQL. THANKS!!!! SELECT Q.ID, Q.InvNo, Q.PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; |
#4
|
|||
|
|||
Is there something wrong with my SQL?
Never mind...I forgot about your missing comma catch.
-- GD "GD" wrote: Thanks, John!! That solved the ranking problem. But why wouldn't it be including the InvNo field as a result? -- GD "John Spencer" wrote: SELECT Q.ID , Q.InvNo , Q.PONo , You are missing this comma in the posted SQL (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; Do you want to start over at 1 for each InvNo and POno combination? That is what you seem to be doing with the above query. If you want one sequence of numbers for all the records, then (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[ID] Q.[ID]) If you want the sequence to restart with each PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) If you want the sequnce to restart with each InvNo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[ID] Q.[ID]) John Spencer Access MVP 2002-2005, 2007-2009 The Hilltop Institute University of Maryland Baltimore County GD wrote: I'm trying to run a make table bringing the ID, InvNo & PONo fields from T09_DupInvs1 table, and I want to rank the PONo field (preferably in order by ID [autonumber]). The result of the SQL below is the ID, PONo and Rank fields, but no InvNo. And the rank is 1 all the way down its field. What am I doing wrong? I'm very new to SQL. THANKS!!!! SELECT Q.ID, Q.InvNo, Q.PONo (SELECT COUNT (*) FROM [T09_DupInvs1] Q1 WHERE Q1.[InvNo] = Q.[InvNo] AND Q1.[PONo] = Q.[PONo] AND Q1.[ID] Q.[ID]) +1 AS Rank INTO T10_DupInvs2 FROM T09_DupInvs1 AS Q ORDER BY Q.ID; |
Thread Tools | |
Display Modes | |
|
|