SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select into
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 08/08/2012 :  22:34:03  Show Profile  Reply with Quote
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 t1
WHERE 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

Edited by - WJHamel on 08/08/2012 22:41:51

chadmat
The Chadinator

USA
1961 Posts

Posted - 08/08/2012 :  22:52:52  Show Profile  Visit chadmat's Homepage  Reply with Quote
SELECT offenseno INTO #Table FROM offense.dbo.off_per
EXCEPT
SELECT OFFENSENO FROM offense.dbo.offense

-Chad
Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 08/08/2012 :  23:03:55  Show Profile  Reply with Quote
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..offense

So, based on that, i've tried to tweak the solution you provided, but to no avail.
Go to Top of Page

chadmat
The Chadinator

USA
1961 Posts

Posted - 08/08/2012 :  23:09:30  Show Profile  Visit chadmat's Homepage  Reply with Quote
SELECT <ColumnList> INTO #Table FROM offense.dbo.off_per
WHERE offenseno NOT IN (SELECT OFFENSENO FROM offense.dbo.offense)


-Chad
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 08/08/2012 :  23:21:37  Show Profile  Reply with Quote
i'm wanting the resultset for the times i run this against different tables to be dropped into a new table

do you mean repeating logic for several tables to populate a common destination table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 08/09/2012 :  09:54:14  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000