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)
 stored procedure

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-07-01 : 01:35:33
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

END




and 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 =803532
select * from EMRTPBilledItems where patient_id =803532
select * from EMRAppointmentDetailsHistory where patient_id =803532

select * from EMRTransactionsTemp where patient_id =803532
--select * from EMRTransactions where patient_id ='803532'
select * from EMRSupplementaryTransactions where patient_id =803532

select * from emrtasklistlkup
select * from EMRFlowDetails where flow_id=1001


i want print statement for as select query based on some conditions in the above procedure


condition 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?

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-07-01 : 02:23:00
i am having a table emrappointmentdetails where visit_type_id is one column.if it is other than 10 then the records in emrsupplementarytransactions should be moved to emrtransactions table.and what ever the records in emrsupplementarytransactions should get deleted.and that paricular table should be updated or inserted by the values from EMRTransactionsTemp table.
i want a select query for this.
Go to Top of Page
   

- Advertisement -