Cari Blog Ini

25 April 2012

How to Use Function Except

Except – function seperti distinct yang mengembalikan row
yang hanya ada pada table sebelah kiri
dan tidak ada pada table sebelah kanan.

-----start-----
SELECT * INTO [Sample_Except_Function_Phone1]
FROM
(
 SELECT Customer_Number FROM [Sample_Except_Function]
 WHERE phone1<>''
) a


SELECT * INTO [Sample_Except_Function_Phone2]
FROM
(
 SELECT Customer_Number FROM [Sample_Except_Function]
 WHERE phone2<>''
) n
-----end-----




Query - 1:
-----start-----
SELECT * FROM Sample_Except_Function_Phone1
EXCEPT
SELECT * FROM Sample_Except_Function_Phone2
-----end-----

Query - 2:
-----start-----
SELECT * FROM Sample_Except_Function_Phone2
EXCEPT
SELECT * FROM Sample_Except_Function_Phone1
-----end-----




About :

01 - Create Function with Return Table in SQL Server
02 - Syntax : CREATE FUNCTION - Return Table - With Parameters
03 - Example of Create Function in SQL with Returns Value
04 - Example of Create Function (No Parameter) in SQL with Returns Value
05 - How to Use Function Intersect
06 - How to Use Function Except