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
 General SQL Server Forums
 New to SQL Server Programming
 Compare two table and match the record.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2009-09-01 : 03:03:00
Dear All,

I am haveing following two tables,queary and their outputs.
In that both table as T_CD_IMPORT and T_BANK_IMPORT_BI haveing same database field as FLEXI_2.
Now i want to match total from both table who's ID same and put the 'M' in FLEXI_2 columns.
Those record are matching put 'M' otherwise put 'P' in FLEXI_2 column.

So can anybody tell me how to write procedure for that ?

SELECT sum(cast(Amount as decimal(18,2))) as CHANN_AMOUNT,PK_CH_SCHEME_ID FROM T_CD_IMPORT
WHERE TRADE_DATE = '4/13/2009' AND cast(AMOUNT as decimal(18,2)) <>0 and flexi_2 IS NULL
group by PK_CH_SCHEME_ID

Output:
3500.00 1
500.00 2
4000.00 5
1000.00 9

SELECT sum(cast(CREDITS as decimal(18,2))) as BANK_CREDIT,PK_SCHEME_ID FROM T_BANK_IMPORT_BI
WHERE DATE = '4/13/2009' AND cast(CREDITS as decimal(18,2)) <>0 and flexi_2 IS NULL
group by PK_SCHEME_ID

Output:
3500.00 1
500.00 2
1000.00 9
6000.00 20

Thnks
Harish Patil

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 06:10:45
join on the common fields and use CASE WHEN in update to check for totals and populate values M /P
Go to Top of Page
   

- Advertisement -