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.
| Author |
Topic |
|
kfluffie
Posting Yak Master
103 Posts |
Posted - 2011-10-22 : 03:33:46
|
| Hi,I have one column, tidpunkt, with a date (2011/10/22 for example) and I have a procedure which are doing some stuff.In this procedure I have a year and a month variable and I want to, based on the column tidpunkt modify some data.How do you check that the column tidpunkt is within the range of the two variables?Variable @startYear = 2011, @startMonth = 10Tidpunkt = 2010/10/13I am not interested in the day and I want the day to be ignored so I can do a equal check on the year and month.Best regards,KF |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-22 : 04:38:37
|
| [code]declare @startYear int = 2011, @startMonth int = 10SELECT DATEADD(mm,@startMonth-1,DATEADD(yy,@startyear-1900,0)) AS PeriodStartDate,DATEADD(mm,@startMonth,DATEADD(yy,@startyear-1900,0)) AS NextPeriodStartDateSELECT *FROM tableWHERE Tidpunkt>=DATEADD(mm,@startMonth-1,DATEADD(yy,@startyear-1900,0))AND Tidpunkt<DATEADD(mm,@startMonth,DATEADD(yy,@startyear-1900,0))[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
kfluffie
Posting Yak Master
103 Posts |
Posted - 2011-10-22 : 06:48:29
|
| Thanks Visakh!I just ended up using DATEPART. I just forgot about it and it seems very convenient to use it here!Best regards,KF |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-22 : 06:56:11
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|