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 |
Sudor
Starting Member
3 Posts |
Posted - 2014-02-03 : 06:08:58
|
HiI am very new to SQL overall and have had the fortune to not be forced to tamper with the existing code.Unfortunatly, one of my exports did not run for 3 days and te query fetches todays date. Could anyone help me with chaning below line to export data for a Specific data instead of current date?WHERE (dbo.fr.ForetagKod = 400) AND (YEAR(dbo.ft.FaktDat) = YEAR(GETDATE())) AND ({ fn MONTH(dbo.ft.FaktDat) } = { fn MONTH(GETDATE()) })Thank you! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-03 : 06:40:24
|
declare @date as a parameter and use below logic...WHERE (dbo.fr.ForetagKod = 400) AND dbo.ft.FaktDat >= @Date AND dbo.ft.FaktDat < @Date + 1 then pass required date value to it to get data for that date------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Sudor
Starting Member
3 Posts |
Posted - 2014-02-03 : 06:56:39
|
Hi Thanks for the reply. But how would I declare the date as a parameter? =) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-03 : 07:00:41
|
quote: Originally posted by Sudor Hi Thanks for the reply. But how would I declare the date as a parameter? =)
if its an adhoc query use DECLAREie likeDECLARE @Date datetimeSET @Date = <pass your value here>.... your queryWHERE (dbo.fr.ForetagKod = 400) AND dbo.ft.FaktDat >= @Date AND dbo.ft.FaktDat < @Date + 1 if its a stored procedure use like belowCREATE PROC GetData@date datetimeAS..... your queryWHERE (dbo.fr.ForetagKod = 400) AND dbo.ft.FaktDat >= @Date AND dbo.ft.FaktDat < @Date + 1GOexecute it likeEXEC GetData <pass your value here> ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Sudor
Starting Member
3 Posts |
Posted - 2014-02-03 : 07:09:49
|
Big thank you! Got it to work. it was a so called "adhoc" query./Sudor |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-03 : 13:41:09
|
ok..cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|