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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to prepare query

Author  Topic 

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 2011-02-25 : 00:26:03
Dear All,

I am using sql server 2005.

I have two table one is master and other is temp with same struncture given below.

Now i need to valide that GIven Itemcode and BatchNo are same in both the table. if not match , Unmatch Itemcode and batchno put in to error table

I have following table structure Like

Master Table
ItemName Itemcode BatchNo
Pencil abc 123
Pencil efg 456
Pencil mnk 789


temp table
ItemName Itemcode BatchNo srno
Pencil abc 123 1
Pencil efg 456 2
Pencil mnk 789 3

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-25 : 04:50:25

-- For Matching Rows
select MT.ItemName,MT.ItemCode,MT.BatchNo
From MasterTable MT
Inner Join TempTable TT on TT.ItemCode=MT.ItemCode and TT.BatchNo=MT.BatchNo

--For Unmatch rows
select MT.ItemName,MT.ItemCode,MT.BatchNo
From MasterTable MT
Left Join TempTable TT on TT.ItemCode=MT.ItemCode and TT.BatchNo=MT.BatchNo
Where TT.ItemCode is null

Cheers
MIK
Go to Top of Page
   

- Advertisement -