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.
| Author |
Topic |
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-08-08 : 22:34:03
|
So i have the following query which i'm using in various ways to find records in one table that are not in another:SELECT offenseno FROM offense.dbo.off_per t1WHERE OFFENSENO not IN (SELECT OFFENSENO FROM offense.dbo.offense t2 WHERE t2.OFFENSENO=t1.OFFENSENO) i'm wanting the resultset for the times i run this against different tables to be dropped into a new table. I've tried tacking a "Select * into " portion at the beginning and turning the above into a subselect, but I'm in syntax hell. So, how do i use the above to make a select into for a new table?thanks |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2012-08-08 : 22:52:52
|
| SELECT offenseno INTO #Table FROM offense.dbo.off_per EXCEPTSELECT OFFENSENO FROM offense.dbo.offense -Chad |
 |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-08-08 : 23:03:55
|
| Sorry, my original query was inaccurate. i'm actually selecting ALL columns from off_per into the new table where the offenseno value is not in offense..offenseSo, based on that, i've tried to tweak the solution you provided, but to no avail. |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2012-08-08 : 23:09:30
|
| SELECT <ColumnList> INTO #Table FROM offense.dbo.off_per WHERE offenseno NOT IN (SELECT OFFENSENO FROM offense.dbo.offense)-Chad |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-08 : 23:21:37
|
| i'm wanting the resultset for the times i run this against different tables to be dropped into a new tabledo you mean repeating logic for several tables to populate a common destination table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-08-09 : 09:54:14
|
| no, basically i'm just modifying the script to run it against different tables, but it should provide the same thing. The last solution provided by Chad seems to work. Thanks all |
 |
|
|
|
|
|