My code is below. I am having a hard time as I am new to SQL to figure out what method would be simpler to use in order to update a column based on differential of dates. Basically what i want to do is if the date is in between today to today minus 7 days (update the symbology_bbl column to week1). the following has been updated.
USE [databasename]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE or Alter PROCEDURE gisuser.GetTheDate
AS
BEGIN
SET NOCOUNT ON;
Declare @rowcount int
Declare @editedDate datetime
Declare @Symbology_BBL nvarchar(25)
Declare mycursor cursor FORWARD_ONLY READ_ONLY LOCAL FOR
select objectID, Edited_Date, Symbology_BBL
from [tablename] order by objectid asc
Open mycursor
fetch next from mycursor
into @rowcount, @editedDate, @Symbology_BBL
while @@FETCH_STATUS = 0
Begin
--if edited_date is from 11/21/2018 to 11/28/2018
begin
set @Symbology_BBL = 'Week1'
end
--elseif edited_date is from 11/15/2018 to 11/20/2018
begin
set @Symbology_BBL = 'Week2'
end
else
begin
set @Symbology_BBL = 'Greater than Week3'
end
--*******************************************************************************
Update [tablename]
set symbology_bbl = @Symbology_BBL
fetch next from mycursor
into @rowcount, @editedDate, @Symbology_BBL
End
Close mycursor
deallocate mycursor
END
Thanks for the help in advance.