HiI've got a query that suppossed to work but it just can't seem to be working so I modified and it seems to be working fine and I just wondering if you guys could tell me why it's not workingDeclare @Enterprise_nbr Char (12) , @Survey_Code VarChar(30) , @Reo_Code char(5) , @User varchar(50) , @Turnover numericSet @User = 'PlayBoy'Set @Reo_Code = 0Declare Insert_EN Cursor read_only forSelect A.Enterprise_nbr, S.turnoverfrom SQL.Agriculture.dbo.Adjusted as Ainner join SQL.Agriculture.koketsom.sample as Son A.Enterprise_nbr = S.Enterprisenbrwhere A.Maint_date is nullOpen Insert_EN Fetch Next from Insert_EN Into @Enterprise_nbr , @TurnoverWhile @@Fetch_Status=0if @Turnover >= 300000 set @Survey_Code = 'Agri2002'Else Set @Survey_Code = 'Agri2003' begin Insert into history_reo (Survey_Code,Enterprise_nbr, Reo_Code, Maint_User_Code ) Values (@Survey_Code, @Enterprise_nbr, @Reo_Code , @User ) Fetch Next from Insert_EN into @Enterprise_nbr, @Turnover, @Survey_Code EndClose Insert_ENDeallocate Insert_EN
The code above ISN'T working so I modified it to this:Declare @Enterprise_nbr Char (12) , @Survey_Code VarChar(30) , @Reo_Code char(5) , @User varchar(50) , @Turnover numericSet @User = 'PlayBoy'Set @Reo_Code = 0Declare Insert_EN Cursor read_only forSelect A.Enterprise_nbr, S.turnover,'AGRI2003' as survey_codefrom SQL.Agriculture.dbo.Adjusted as Ainner join SQL.Agriculture.koketsom.sample as Son A.Enterprise_nbr = S.Enterprisenbrwhere A.Maint_date is nulland s.turnover >= 300000unionSelect A.Enterprise_nbr, S.turnover,'AGRI2002' as survey_codefrom SQL.Agriculture.dbo.Adjusted as Ainner join SQL.Agriculture.koketsom.sample as Son A.Enterprise_nbr = S.Enterprisenbrwhere A.Maint_date is nulland s.turnover < 300000order by A.Enterprise_nbrOpen Insert_EN Fetch Next from Insert_EN Into @Enterprise_nbr , @Turnover, @Survey_CodeWhile @@Fetch_Status=0 begin Insert into history_reo (Survey_Code,Enterprise_nbr, Reo_Code, Maint_User_Code ) Values (@Survey_Code, @Enterprise_nbr, @Reo_Code , @User ) Fetch Next from Insert_EN into @Enterprise_nbr, @Turnover, @Survey_Code EndClose Insert_ENDeallocate Insert_EN
Can somebody tell me why the first query isn't working. I let it run for about 25 minutes and it hadn't returned anything.You can't teach an old mouse new clicks.