Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Question

Status
Not open for further replies.

luceze

Programmer
Apr 26, 2001
842
US
When i am running a union query on three tables it treats the select statement as if the distinct property was there is there any way to pull all the records. I included the code if you want to look at it.

SELECT DATE_ENTER, FUND, FUNCTION, OBJECT, SUB_OBJT, ORG, FND_YEAR, PROGRAM, NUMBER, REASON, AMOUNT, FIELD_IND, [fund] & "-" & [function] & "-" & [object] & "-" & [sub_objt] & "-" & [org] & "-" & [fnd_year] & "-" & [program] AS CODE
FROM FINYCASH
WHERE (((FUND) Between 100 And 200 And Not (FUND)=102) AND ((OBJECT) Between 5000 And 6000) AND ((FND_YEAR)="1"))
ORDER BY ORG;

UNION SELECT [DATE_ENTER], [FUND], [FUNCTION], [OBJECT], [SUB_OBJT], [ORG], [FND_YEAR], [PROGRAM], [NUMBER], [REASON], [AMOUNT], [FIELD_IND], [fund] & "-" & [function] & "-" & [object] & "-" & [sub_objt] & "-" & [org] & "-" & [fnd_year] & "-" & [program] AS CODE
FROM FINYGENJ WHERE ((Not (FUND)=102) AND ((OBJECT) Between 5000 And 6000) AND ((FND_YEAR)="1") AND ((FIELD_IND)="3"))
ORDER BY ORG

UNION SELECT DATE_ENTER, FUND, FUNCTION, OBJECT, SUB_OBJT, ORG, FND_YEAR, PROGRAM, NUMBER, REASON, AMOUNT, FIELD_IND, [fund] & "-" & [function] & "-" & [object] & "-" & [sub_objt] & "-" & [org] & "-" & [fnd_year] & "-" & [program] AS CODE
FROM REVFINYCHK
WHERE (((FUND) Between 100 And 200 And Not (FUND)=102) AND ((OBJECT) Between 5000 And 6000))
ORDER BY ORG;

 
In your code after the first block of the select statement you have a ";" which would cause the engine to stop as soon as it reads that because it thinks the select statement is done. Not sure if that's your problem but was the only thing I noticed.

HTH Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top