how to Sub query using in cursor in sqlserver
I am trying sub query using data insert,but two tables not match id but that not match id inserted previous record get it automatically inserted table, so i want match id only inserted my data.
MY Query Is:
select TOP 1 EID from BATCHID,CO_BATCH_MASTER CBM where CBM.cbm_active<>'D' and cbm_batch_start_dt<@cbm_batch_start_dt and CBM.cmn_minor_code=@cmn_minor_code and EID=(select EID from BATCHID where BID=CBM.cbm_batch_id and B_ACTIV<>'D') ORDER BY cbm_batch_start_dt DESC
Example:
My table not batchid available(another table id )but previous record value get same repeat record inserted my table this one error.example below:
IDCERBID CEREID B_ACTIVE UserId E_dt
2481B5893 AFF/B240 A Nirmal 2014-09-22 19:30:59.200
2482B5894 PSCRB/B174 A Nirmal 2014-09-22 19:30:59.313
2483B5086 TFC/B364 A Nirmal 2014-09-22 19:30:59.413
2484B6252 FPFF/B700-this record repeat below same CEREID insert below data not match id this data
2485B6298 FPFF/B700 A Nirmal 2014-09-22 19:30:59.517
2486B7595 FPFF/B700 A Nirmal 2014-09-22 19:30:59.517
2487B7621 FPFF/B700 A Nirmal 2014-09-22 19:30:59.517
2488B7622 FPFF/B700 A Nirmal 2014-09-22 19:30:59.843
2489B6509 MFA/B517 A Nirmal 2014-09-22 19:30:59.940
I want two tables not match batch id means that data not inserted table below sample record insert my table.
IDCERBID CEREID B_ACTIVE UserId E_dt
2481B5893 AFF/B240 A Nirmal 2014-09-22 19:30:59.200
2482B5894 PSCRB/B174 A Nirmal 2014-09-22 19:30:59.313
2483B5086 TFC/B364 A Nirmal 2014-09-22 19:30:59.413
2489B6509 MFA/B517 A Nirmal 2014-09-22 19:30:59.940
Thanks