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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 newbie questions 1

Status
Not open for further replies.

RoyceyBaby

IS-IT--Management
Mar 23, 2001
22
Hi everybody,

I have 2 questions that I hope somone can help me on or point me in a different direction.

1) Is it possible in a SP to run a query on a table to produce a set of results and then to use that set of results as the basis of another query?

2) I have two tables A and B, B contains ammended versions of certain records contained in A. How do I combine A and B together and not include records from A which I have ammended and put in B.
e.g

A B
AID x y z BID AID x y z
1 12 23 34 1 3 63 82 17
2 45 65 35 2 4 26 26 43
3 63 82 16
4 25 25 72
5 73 27 52

Combine them to produce

C
AID x y z
1 12 23 34
2 45 65 35
3 63 82 17
4 26 26 72
5 73 27 52

Many thanks,

Royce
 
1) Yes; you can select into a temporary table (one preceded with "#"), then use that in the second query.

2) Depends on whether you have a primary key in Table A (not necessarily one declared as a PK, just one that will work as one).

If you do, then you can use WHERE MyColumn NOT IN ... I didn't go further, because I'm not sure which way you want them combined - as additional columns or as additional rows. Robert Bradley
Coming Soon:
 
Hi Royce, another thing to try...

SELECT * FROM a
WHERE aid NOT IN (SELECT aid FROM b)
UNION
SELECT aid, x, y, z FROM b

Andel
andelbarroga@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top