Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi, I want to calculate dates using storedprocedures.The condition is when the user selects dates as 2nd Aug2006 to1st Aug2007 it should validate with the table where year has already been defined for eg in my case I have a Table Year where the values are 1year,2 year...when the user selects period of one year it should check for the existence in my table Year and vice versa. Hope u can find me a solution ....... Any help would be appreciated..... Thanks in Advance
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-08-07 : 04:10:17
can you post your table structure, some sample data and the result that you want ?KH
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-08-07 : 04:17:27
Well it will be better if you can post some sample data.. Just check if this satisfy your requirment.
If Exists (Select * From [Year] Where <YearColumn> = (DateDiff(Month,'20060802','20070801')/12)
Chirag
roxcy
Yak Posting Veteran
58 Posts
Posted - 2006-08-07 : 05:49:32
Hi Khtan, I am using two datecontrols ie fromdate and todate.On selecting the dates i want to check whether the dates selected is for the period of 1 year 2 year.I would like 2 check this using stored procedures.So how should i do the calculation part?Hope u got my point... Roxcy..
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-08-07 : 05:59:35
Somthing like this..??
Create Proc CheckPeriod(@pStartDate DateTime, @pEndDate DateTime,@pInterval int out)AsBegin Select @pInterval = Datediff(month,@pStartDate,@pEndDate)/12 return @pInterval End
This will return you the interval in the variable @pInterval. Chirag