hi,this is my stored procedure.Begin Declare @appointmentIds varchar(4000), @cnt int, @SQL nvarchar (4000), @TSQL nvarchar (4000); DECLARE appmt_Cursor CURSOR FAST_FORWARD FOR select appointment_ids from EMRTPBilledItems where tp_item_id='KA02-D0096' and appointment_ids is not null; OPEN appmt_Cursor FETCH NEXT FROM appmt_Cursor INTO @appointmentIds; WHILE @@FETCH_Status = 0 BEGIN EXEC ('Declare task_Cursor CURSOR FOR select ID_VALUE from EMRSupplementaryTransactions where task_id=2 AND ID_VALUE IN (select appointment_id from EMRAppointmentDetails where appointment_id IN ('+ @appointmentIds + ')) ') Open task_Cursor FETCH NEXT FROM task_Cursor INTO @TSQL; WHILE @@FETCH_Status = 0 BEGIN PRINT @TSQL;---------------------required statements FETCH NEXT FROM task_Cursor INTO @TSQL; End CLOSE task_Cursor DEALLOCATE task_Cursor FETCH NEXT FROM appmt_Cursor INTO @appointmentIds; END CLOSE appmt_Cursor DEALLOCATE appmt_Cursor ENDand i have some tables like select * from sysobjects where name like '%flow%'select * from emrpatientsmaster where patient_id like '%3532'select * from EMRAppointmentDetails where patient_id =803532select * from EMRTPBilledItems where patient_id =803532select * from EMRAppointmentDetailsHistory where patient_id =803532select * from EMRTransactionsTemp where patient_id =803532--select * from EMRTransactions where patient_id ='803532'select * from EMRSupplementaryTransactions where patient_id =803532select * from emrtasklistlkupselect * from EMRFlowDetails where flow_id=1001i want print statement for as select query based on some conditions in the above procedurecondition 1:if emrappoitmentdetails table value is inserted intially status column is 1 and corresponding emrappointmentdatailshistory table will be with 2 rows as status =1,2 based on atrigger.2)EMRSupplementaryTransactions table and EMRTransactions will be one value inserted.here task_id will be 2 as it is identical to the status id column from emrappointmentdetailshistory table.3)now record from EMRSupplementaryTransactions will be deleted and inserted the same for EMRTransactions table.4)what ever the values in EMRTransactionsTemp table should be updated to EMRSupplementaryTransactions finally.these are all the conditions i need out in a select query can anyone help me out for this?