Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help creating a UNION in a SQL!!
Message
 
To
02/11/1999 16:50:21
Peter Brama
West Pointe Enterprises
Detroit, Michigan, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00285763
Message ID:
00285769
Views:
15
Hi Peter,

If you use UNION in a SELECT-SQL statement, the number and data type of the columns returned by BOTH the primary and union-ed selection statements MUST BE IDENTICAL.

Programming UNION-s can be tricky (g). I would probably start by directing the results of the first SELECT to a *table* rather than a cursor. This might make the second SELECT a bit easier to accomplish.

HTH,
Evan Pauley

>I am using 2 SQL statements to build a cursor to be used for a report.
>The first SQL creates 3 "fields" that are based on SUMs of a variety of records from 3 seperate files.
>
>The second SQL takes the first SQL's cursor and adds it's fields to another large SQL statement that provides the detail from again 3 seperate files + the first SQL cursor.
>
>I thought this was working well UNTIL, the second SQL did not find any records that matched the search criteria for a particular client BUT the fields from the 1st SQL had values. The final record was completely dropped even though I needed the 1st SQL values to printout.
>
>It has been suggested that I either....
>
>make the 2nd SQL cursor writeable and codingly ADD the first SQL records to the cursor verbatim
>
>or
>
>use a UNION to join the 2 SQL with probably an ALL statement to get all records from BOTH SQLs.
>
>
>I tried the UNION and keep getting coding errors. The problem is, I don't know how to CODE....
>
>in the first SQL the place holders for the fields that are in the second SQL. They vary from text, numeric and dates. Then in the second SQL the place holders for the fields from the first SQL that were all SUMs of amount fields.
>
>Apparently my problem is that I don't have the right number of fields and/or the right types. What I am running into is the first SQL isn't looking at all the same files so I don't have the field names to reference or whatever I need to do to get them.
>
>Can someone explain this better than the online help and maybe give me a simple (yea right - is there such a thing with unions?) example or two?
>
>
>Thanks
Evan Pauley, MCP
Positronic Technology Systems LLC
Knoxville, TN

If a vegetarian eats vegetables, what does a humanitarian eat?
Previous
Reply
Map
View

Click here to load this message in the networking platform