Please see the row below:
FID | IssueDate | IssueType | Status
46128 | 2010-12-30 00:00:00.000 | 2 | 1
I am stucked at a very stupid thing, that a beginner can do well too. I need to update the above row. I have already asked the solution for same in various ways but did’nt achieved yet. I dont know why????.
Let me explain the above
FID is my primary key, Issue Date is my sticker issue date, issue type is my type of sticker and status is current status of sticker.
Now what i want is to check the issue date with current years 1st April. If the system date has changed from 31st March , which is the fixed last date for expiration, the row’s status will automatically get expired and status will get changed from 1 to 3.
I am using the given query , after executing it says 0 rows updated. please guide me where i am making mistake.
ALTER PROCEDURE [dbo].[spMakeStickerVoid]
(
@FisherId BIGINT,
@ManipulatedByUser VARCHAR(50),
@OPParam INT OUTPUT
)
AS
BEGIN
DECLARE @CurrentDate as DATETIME,
@FirstAprilOfCurrentYear AS DATETIME
SET @FirstAprilOfCurrentYear = (select dateadd(month,datediff(month,0,getdate()) ,'18990401'));
SET @CurrentDate = GETDATE();
--SET @OPParam =0
IF @CurrentDate >= @FirstAprilOfCurrentYear
BEGIN
UPDATE tblStickerInfo
SET StatusId = 3
WHERE FisherId = 46128 AND (IssuedDate < @FirstAprilOfCurrentYear) AND StatusId = 1
END
--SET @OPParam =1
END
UPDATE:
Actually, there are few conditions
**
1. It should occur every year 1st April or onwards.
2. All issue dates that are on or before 31st March of that year will get
expires, status =3
3. So i put a check if current date is 1st april or greater than that.
because there might be a condition if the system was switched off on 1st april
and started working on 4 th April. So even in this case the stickers prior to
1st april will have to expire.
4. For making my query clear, just take an example of Insurance policy ,
which is only valid for a year. Like if i have registered it on 28th Jan2011,
then it will automatically get expired on next year 27th Jan 2012 midnight.
But here in my case date is fixed to 31st March midnight every year.
5. Columns names and parameters are not an issue here, i had
placed somewhat diff here consider FID = FisherId
6. Need a query that will automatically populate the @FirstAprilOfEveryYear
with first april of that year, so that it will be carried out automatically.
**
@FirstAprilOfCurrentYearis the first of april of 2010 which means that(IssuedDate < @FirstAprilOfCurrentYear)is not true.This might do what you want