albert albert

albert albert

  • NA
  • 524
  • 0

Making QUErY from stored procedure to SQL

Sep 9 2013 7:04 AM
HI everybody,

I have this:

[code]
OPEN @WeekdayCursor
--
--SET @Weekdays = ''
--FETCH NEXT FROM @WeekdayCursor
--INTO @PriceAddID, @StartDate, @EndDate, @Weekdays
--
--WHILE @@FETCH_STATUS = 0
--BEGIN
--DECLARE @Position int
--  SET @Position = 0
--
--  DECLARE @NumDays int
--  SET @NumDays = DATEDIFF(day, @StartDate, @EndDate)
--
--  DECLARE @CurrentDate    datetime
--  DECLARE @CurrentBWeekday  int
--  DECLARE @Weekday int
--
--  WHILE (@Position < @NumDays + 1)
--  BEGIN
--    SET @CurrentDate = DATEADD(day, @Position, @StartDate)
--    -- Remember, SET DATEFIRST 1 for Monday
--    SET @CurrentBWeekday    = dbo.f_BWeekday(@CurrentDate)
--    -- Validate the weekday
--      --SET @Position = @Position + 1
--  IF (@Weekdays > 0 AND @CurrentBWeekday & @Weekdays <> @CurrentBWeekday)
--    BEGIN
--      SET @Position = @Position + 1
--      CONTINUE
--    END
--  SET @Weekday= (SELECT dbo.f_Bweekday(@CurrentDate))
--    INSERT INTO #weekdayprice VALUES(@PriceAddID, @StartDate, @EndDate, @Weekday)
--    SET @Position = @Position + 1
--  END
--
----Logic
--FETCH NEXT FROM @WeekdayCursor
--INTO @PriceAddID, @StartDate, @EndDate, @Weekdays
--END
--
--CLOSE @WeekdayCursor
--DEALLOCATE @WeekdayCursor
[/code]

But I want to make a query of it. Because If you execute the weekDayCursor then the performance is very slow, like 20 minutes.

THX

Answers (7)