• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

EDIT: Nevermind, figured it out...Help with this basic query in SQL Server?

I have a report that runs monthly and posts prior month statistics. As of this month, it is not populating my tables. Here is my query.

Code:
[FONT=Courier New]
INSERT DVMS_FUEL_DRIVERS_FINAL (MonthYear,Weight,DriversFueling)[/FONT]
[FONT=Courier New]SELECT MonthYear,Weight,DriversFueling
FROM viewFuelDriversFinal
[B]WHERE month(MonthYear) = month(getdate())-1[/B][/FONT]
I will step through how I think the bold line is processing.

month(12/1/2010) = month(1/11/2011) - 1
12 = 1 - 1
12 = 0

Is this a correct assumption? How can I get it to pull '12' instead of '0'?

Edit:
I decided just to hard code in the 12 for now. This is a once a year occurrence so I'll just suck it up 😛
 
Last edited:
It looks like you worked around the problem, rather than figuring it out as the edited title implies, so I will leave the thread open unless you want it closed.
 
I encountered a similar problem. What you need to use, is the Datediff function.

Its parameters are as follows: datediff(datepart,startdate,enddate)
Example would be: datediff(month,getdate(),MonthYear)

🙂
 
Last edited:
Back
Top