Cursor EXample
--------------
DECLARE @appointmentid varchar(max),@visitid bigint,@exvisitid varchar(max)
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
select Appointmentid,visitid,exvisitid from pac
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @appointmentid ,@visitid,@exvisitid
WHILE @@FETCH_STATUS = 0
BEGIN
insert into TblStudy
([Studytypeid],[VisitId],[MachineId],[ReferalID],[UserID],[DateTime],[AppointmentId],[StudyState],[ScheduledTime],[RegisteredTime],[ScheduledUserId],[RegisteredUserId],[Scantype],[PackageID],
[Billamount],[Billdiscount],[ExtraAmount],[Obsolete],[CenterId],[ExVisitId])
values
(26068,@visitid,62,3687,0,'2011-06-16 12:49:42.460',@appointmentid,1,'2011-06-16 08:52:00.000','2011-06-16 12:49:46.023',90,90,'P',26443,0,0,0,0,2,@exvisitid)
FETCH NEXT
FROM @getAccountID INTO @appointmentid ,@visitid,@exvisitid
END
CLOSE @getAccountID
DEALLOCATE @getAccountID
---------------------------------------------------------------------------------------
DECLARE @appointmentid varchar(max)
DECLARE @getAccountID CURSOR
SET @getAccountID = CURSOR FOR
select distinct AppoinementID from tblappointmenttrans where AppoinementID in (12030,12034,12035,12036,12037,12039,12041,12042,12043,12044,12045,12046,12047,12048,12049,
12050,12051,12052,12053,12054,12056,12057,12059,12060,12061,12062,12063,12064,12065,12066,12067,12068,12069,12070,12071,12072,12073,12074,12075,12076,12077,12078,12079,12080,12081,12082,
12083,12084,12085,12086,12087,12088,12089,12090,12092,12093,12096,12098,12100,12101,12102,12103,12104,12106,12107,12108,12109,12111,12112,12115,12116,12117,12119,12120,12121,12122,12123,
12124,12125,12126,12127,12128,12129,12130,12133)
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @appointmentid
WHILE @@FETCH_STATUS = 0
BEGIN
insert into TblAppointmentTrans ([BillingID],[MachineID],[DocUserID],[DATED],[TIMED],[AppoinementID],[ASessionid],Scantype],[PackageID],[BillingAmount],[AppStatus],[ExtraAmount],[Discount], [PaidAmount],
[Obsolete],[CenterId],[FutureAppointment],[SourceCard],[FreeTest])
values (26068,62,74,'2011-06-16 08:52:00.000','2011-06-16 08:53:00.000',@appointmentid,'vpi-uwinsvr-6/16/2011 12:48:44 PM48833','p',26443,0,1,0,0,0,0,2,0,'NO','F')
FETCH NEXT
FROM @getAccountID INTO @appointmentid
END
CLOSE @getAccountID
DEALLOCATE @getAccountID
--
--
No comments:
Post a Comment