A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Is there something wrong with my SQL?



 
 
Thread Tools Display Modes
  #1  
Old August 6th, 2009, 02:42 PM posted to microsoft.public.access.gettingstarted
gd
external usenet poster
 
Posts: 209
Default 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  
Old August 6th, 2009, 03:52 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default 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  
Old August 6th, 2009, 04:02 PM posted to microsoft.public.access.gettingstarted
gd
external usenet poster
 
Posts: 209
Default 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  
Old August 6th, 2009, 04:10 PM posted to microsoft.public.access.gettingstarted
gd
external usenet poster
 
Posts: 209
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.