Cari Blog Ini

25 April 2012

How to Use Function Intersect

Intersect – function seperti distinct yang mengembalikan row yang match pada kedua table.

-----start-----
SELECT * INTO [Sample_Intersect_Function_Phone1]
FROM
(
 SELECT Customer_Number FROM [Sample_Intersect_Function]
 WHERE phone1<>''
) A



SELECT * INTO [Sample_Intersect_Function_Phone2]
FROM
(
 SELECT Customer_Number FROM [Sample_Intersect_Function]
 WHERE phone2<>''
) N
-----end-----


Query - 1:
-----start-----
SELECT * FROM Sample_Intersect_Function_Phone1
INTERSECT
SELECT * FROM Sample_Intersect_Function_Phone2
-----end-----

Query - 2:
-----start-----
SELECT * FROM Sample_Intersect_Function_Phone2
INTERSECT
SELECT * FROM Sample_Intersect_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