Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SPROC Question

Author  Topic 

rhoenig
Starting Member

11 Posts

Posted - 2005-08-30 : 14:53:57
I would like to create an SPROC that will select all the items from Table A that are not in Table B. How can I do this?

Thank you
Robert

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-30 : 14:57:29
Here you go:



CREATE TABLE t1 (Column1 int NOT NULL)
CREATE TABLE t2 (Column1 int NOT NULL)

INSERT INTO t1 VALUES(1)
INSERT INTO t1 VALUES(2)
INSERT INTO t1 VALUES(3)
INSERT INTO t2 VALUES(1)
INSERT INTO t2 VALUES(2)

SELECT t1.Column1 AS T1COLUMN1
FROM t1
LEFT OUTER JOIN t2
ON t1.Column1 = t2.Column1
WHERE t2.Column1 IS NULL

DROP TABLE t1, t2



Wrapping the SELECT in a stored procedure should be trivial.

Tara
Go to Top of Page

rhoenig
Starting Member

11 Posts

Posted - 2005-08-30 : 15:30:03
Thanks that did it.
Go to Top of Page
   

- Advertisement -