Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have following data in table

UserId -- SubscriptionID -- PackageID -- Balance -- Start Date -- End Date -- IsActive -- IsPaid

5      --       16       --     2     -- 300     --  6-6-2014  -- 6-7-2014 --   True   --  True
5      --       18       --     3     -- 200     --  6-5-2014  -- 6-6-2014 --   True   --  True
5      --       20       --     2     -- 300     -- 25-6-2014  -- 25-7-2014 --   True   --  True 

I have userID and input parameter and want to do

get all user subsciption id of @user
then Check for the all subscription where iSactiv = true, If today is Enddate or balance = 0 then set IsActive = false else skip

i have write this query but it says error that multiple rows are getting....

SQL
UPDATE TblSubscription 
SET 	IsActive = 0 
WHERE 	 
UserId = @userid 
and  SubscriptionId = (SELECT SubscriptionId FROM  TblSubscription  WHERE TblSubscription.UserId = @userid and TblSubscription.IsActive = 1 and TblSubscription.IsPaid = 1) 
and  GETDATE() > FinishDate
OR   MaxNotification < = 0
OR 	 MaxArticles < = 0
OR 	 MaxVideos 	< = 0
OR 	 MaxEvent  < = 0
Posted
Updated 18-Jun-14 0:37am
v3
Comments
Nandakishore G N 18-Jun-14 5:58am    
Paste what have you done till now

1 solution

SQL
Create Proc uspCheckUserSubscriptionstatus
@success  bit out,
@userid int
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
UPDATE TblSubscription
SET IsActive = 0 
WHERE 
(FinishDate < GETDATE()
OR ( MaxNotification < = 0 and 	 MaxArticles < = 0 and 	 MaxVideos 	< = 0 and 	 MaxEvent  < = 0 ))
and   IsActive = 1
and UserId = @userid
SET @success = 1
END TRY
BEGIN CATCH
SET @success = 0
END CATCH
END
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900