SQL Server - exclusion resulting collection
Asked By Pete
28-Oct-08 03:23 PM
Hi folks,
I have a exclusion question. I am listing the following code after
this. Is there is a way using SQL code to get the exclusion set without any
concatenations or LINQ solution. Thanks.
Peter Kao
create table #t1
(
id int,
name varchar(20)
)
go
insert #t1 values(1, 'aaa')
insert #t1 values(2, 'bbb')
insert #t1 values(2, 'ccc')
go
select * from #t2
create table #t2
(
id int,
name varchar(20)
)
go
insert #t2 values(1, 'aaa')
insert #t2 values(2, 'bbb')
go
-- question, the sql code
-- rows in #t1, not in #t2
-- all matches, 2,'ccc'
SQL Server 2005
(1)
Varchar
(1)
LINQ
(1)
Int
(1)
Mr Tea replied...
You mean EXCEPT ?
select id, name from #t1
EXCEPT
select id, name from #t2
Mr Tea
Plamen Ratchev replied...
On SQL Server 2005/2008 you can use EXCEPT:
SELECT id, name FROM #t1
EXCEPT
SELECT id, name FROM #t2;
--
Plamen Ratchev
http://www.SQLStudio.com
SQL Server Why_can’t_recursive_queries_contain. . .? hi I hope I didn = 92t put too many questions 1) Why can such as this is already a strong case to simply disallow the option. - - Hugo Kornelis, SQL Server MVP My SQL Server blog: http: / / sqlblog.com / blogs / hugo_kornelis MS SQL Server is a minimal subset of the ANSI / ISO Standards. In Standard SQL, the WITH clause
SQL Server What's the go with sql server I was just saying today that sql server is full of silly limitations and I seem to hit on a new one every features with more ways to manipulate things than you can poke a stick at. In sql server we don't even have a full range of date functions (a pretty basic feature
SQL Server How do I pass multiple values into a parameter? Hi, We have a SQL Server machine that is hosting our internal application's database. We also have another server running MS GreatPlains. In a user defined field in GP, we put our ProjectIDs. This procedure? The ProjectID is an integer. I tried to put all ProjectIDs in a single varchar parameter separated by commas and changed the syntax in the SELECT statement from: WHERE ProjectID to WHERE ProjectID IN (@ProjectIDs) but this didn't work. I received unable to convert varchar to int error message. How can I pass multiple ProjectIDs in to a single SELECT statement where
SQL Server Select first three words in field Hi I need to select the first three words in a varchar field and then the remaining words (4 to whatever) separately. For my purposes I count to do that? Many thanks in advance for any help. Regards Tim P declare @s varchar(100) SET @s = 'The House of Commons Members Library Meeting Rooms' SELECT SUBSTRING(@s, 1 than 3 spaces in the sentence this will not be accurate): CREATE TABLE Foo ( keycol INT PRIMARY KEY, datacol VARCHAR(100)); INSERT INTO Foo VALUES(1, 'The House of Commons Members Library Meeting Rooms'); SELECT a Numbers table (see http: / / www.aspfaq.com / show.asp?id = 2516) and are on SQL 2005 or later and need to handle cases where the column has fewer than three words
SQL Server OUTPUT INTO I'm trying to log before and after states using OUTPUT INTO in fogetting some syntax this gives an error on the second 'into' CREATE PROCEDURE Assignments @Person varchar(65), @Project char(5), @Sep float, @Oct float, @Nov float, @Dec float, @Jan float, @Feb float, @Mar float, @Apr float, @May float, @Jun float, @Jul float, @Aug float, @cUser varchar(65), @Type varchar(10) As Begin Try If (@Type = 'New') begin insert into MonthHours (Person, Project, Sep, Oct that! Hm, that does not look like a good CATCH handler to me. - - Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http: / / msdn.microsoft.com / en-us / sqlserver / cc514207.aspx SQL