Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SPT - multiple SELECTs with single result set
Message
From
09/07/2006 11:50:09
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
07/07/2006 16:19:49
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01134421
Message ID:
01134780
Views:
19
>>>It's a series of SQL SELECTs with no intermediate processing.
>>>
>>>It roughly goes as follows:
>>>
>>>- SELECT a subset of records with specific characteristics (has a UNION)
>>>- SELECT some records INNER JOINed on first above
>>>- 4 UNIONed SELECTs to get additional records of interest also INNER JOINed on first above
>>>- FULL JOIN of last 2 above, producing result set of interest. All other results ignored.
>>>
>>>It just seems to me that I should be able to do this using SPT, returning the single final cursor of interest.
>>
>>I don't know of any other way but to use #temp tables.
>>
>>
Select ,,,
>>   into #temp1
>>   from ... Union select ,,, ...
>>select , , ,
>>   into #temp2
>>   from ...
>>   inner join #temp1 on ...
>>select , , , into #temp3 from ...
>>   union select , , , from...
>>   union select , , ,...
>>select , , , from #temp2
>>   full join #temp3 on ...
>>-- I usually do this because they seem to vanish only when you disconnect
>>drop table #temp1
>>drop table #temp2
>>drop table #temp3
>>
>>And that's it. I'm doing this quite often, when speed requires and when all I need is on the server. Sometimes there's still some more to do in VFP later, depending on where the rest of the data are (i.e. I may have pulled some other recordset already, and it's simpler to reuse it in Fox than to pull the same set again for purity's sake).
>
>Yes, that's what I want to do.
>So all I have to do is to DROP the intermediate table, leaving only the one of interest to be returned?

The intermediate tables will be dropped automatically when you disconnect from the SQL server. Of course, you may run something like this more than once during a single session, and you may then get an error when you select into a table which already exists. The cure is to either check for their existence beforehand and drop them if they're already there, or to do a cleanup afterwards.

>I assume the number sign (pound sign, etc "#") is NOT any kind of keyword?

Well it is - it means that the table is temporary and to be dropped when you disconnect. Internally, these names translate into something 32 or 127 characters long, with some sort of connection ID appended and filled with underscores - you can see that if you look at the tmptables database (or something like that) with query analyzer or some other tool while you had these created in the first connection.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform