如何在定义游标的时候使用动态sql语句
declare @GetCaridStr Nvarchar(1000) ;
set @GetCaridStr = 'DECLARE LandAreaO_Cursor CURSOR FOR select carid from car_info where companyid not in(select companyid from company_info where list2 =543 and list3 =543 and status =1) and car_type in ('+ @Key_CarType +')';
Exec(@GetCaridStr) ;
OPEN LandAreaO_Cursor;
FETCH NEXT FROM LandAreaO_Cursor INTO @CarID;
WHILE @@FETCH_STATUS = 0
BEGIN
set @LandArea = dbo.Monitor_GetArreaLand(@CarID,@queryDate);
update landarrea set area =convert(float,@LandArea) where
carid =@CarID and queryDate = @queryDate;
FETCH NEXT FROM LandAreaO_Cursor INTO @CarID;
END
CLOSE LandAreaO_Cursor;
DEALLOCATE LandAreaO_Cursor;