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

SQL
Create Table TblSubscription
(
SubscriptionId int identity(1,1) Primary key,
UserId INT NOT NULL Foreign key References TblAppUser(UserId),
PackageId INT NOT NULL Foreign key References TblPackages(PackageID),
StartDate datetime,
FinishDate datetime,
mxnotification int,
mxarticles int,
mxvideos int,
mxevent int,
mxallias int,
IsActive bit,
IsPaid bit
);


SQL
INSERT INTO TblSubscription (UserId,PackageId,StartDate,FinishDate,mxnotification,mxarticles,mxvideos,mxevent,mxallias,IsActive,IsPaid)
VALUES(@UserID,@PackageId,GetDate(),GETDATE()+30,@notific,@articles,@mxvideos,@mxevent,@mxallias,0,0) SELECT @@IDENTITY


I want that column name startdate= GEtdate() and finshdate=getdate()+30 equals. it automaically sets IsActive = false for that Userid
And Ifmxnotification,mxarticles,mxvideos,mxevent,mxallias =0 it also automatically sets IsActive =false for that Userid

How can i do that. is there any function or other stuff available.
Posted

1 solution

What does the '30' refer to in your sql query? Is it month, year, millisecond, etc? I believe what you're after is the
SQL
DATEADD(datepart, number, date) //number is an Integer
function. If you're adding month to the current date (GETDATE()) then your portion of the query will look like this
SQL
...values(..., DATEADD(day, 30, GETDATE(),...)
Now, if you're just trying to get 30 days out from your current date and the following is equivalent to the above:
SQL
...values(..., DATEADD(month, 1, GETDATE(),...


Here is more information to get yourself familiar with the DATE function in SQL Server.
http://technet.microsoft.com/en-us/library/ms186819(v=sql.100).aspx[^]

Hope that helps...
SS
 
Share this answer
 

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