September 18, 2012 at 11:17 am
Good Day To All,
I'm working on a budgetreport that ask the user to enter the up to date.
If the user enters let's say 08/2012 I'm able to get actual data from the begin of the beginning of the year to the end of the month of 08/2012.
My problem is now the user wants to get the budgeted data for the remaining part of the year. For this example I need 09/2012 through 12/2012 budget data.
This is what I have so far but doesn't work properly.
sum(CASE When t.uMonth between dateadd(m,11,dbo.get_boy(dateadd(m, month('#date2#') + 1,'#date2#'),p.hmy)) and dateadd(m,11,dbo.get_boy(dateadd(y,1,'#date2#'),p.hmy))
THEN
CASE a.iNormalBalance WHEN 1
THEN l.dpercent*.01*isnull(-t.sBudget,0)
ELSE l.dpercent*.01*isnull(t.sBudget,0) END
ELSE 0 END ) data8,
***dbo.get_BOY is a function that get Beginning Of Year
*** #date2# ***** is a parameter that is entered by the user
**** data 8 is the placeholder for the end result.
**** a.iNormalBalance is a flag field when 1 do something when it's 0 do something else
*** u.month is the month I test against from the enter parameter
Thanks
September 18, 2012 at 11:45 am
Instead of using UDFs (dbo.get_BOY) that will reduce performance, try looking at this article.
http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/
September 18, 2012 at 6:45 pm
Agreed that the BOY function is a waste of CPU cycles when the conversion is quite easy as follows:
SET DATEFORMAT MDY
SELECT BOY=DATEADD(year, DATEDIFF(year, 0, MyDate), 0)
,EOY=DATEADD(year, 1, DATEADD(year, DATEDIFF(year, 0, MyDate), 0))-1
FROM (SELECT CAST(REPLACE('08/2012','/','-01-') AS DATETIME)) a(MyDate)
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
September 18, 2012 at 8:06 pm
CELKO (9/18/2012)
I don't want to post it again, so Google around here for "Report_Periods"; it is a basic look-up table for temporal durations. Don't use UDFs; they screw up the optimizer, cannot port and are a bitch to maintain.
Please ignore this stupid remark!
Although in your case UDF is not really required, they are very helpful and useful where appropriate.
UDF is a powerful feature of SQL Server and when UDFs implemented correctly, they do not screw up the optimiser. If you thinking to port your system into other RDBMS, believe me, having UDFs will not be your main concerns. They are not harder to maintain than stored procedures.
Mr. Celko hates many different features of SQL Server (which he cannot comprehend) and he is very vocal about it...
September 18, 2012 at 8:25 pm
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!
Easy, big guy. You're right but that's something that he would say. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2012 at 6:20 am
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
September 19, 2012 at 7:14 am
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
😛
--Jeff Moden
Change is inevitable... Change for the better is not.
September 20, 2012 at 7:12 am
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
You should have used a nullable column, and just removed the adjective entirely...
---------------------------------------------------------
How best to post your question[/url]
How to post performance problems[/url]
Tally Table:What it is and how it replaces a loop[/url]
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
September 20, 2012 at 7:38 am
jcrawf02 (9/20/2012)
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
You should have used a nullable column, and just removed the adjective entirely...
Sorry, but it's not nullable in my database. The remark was stupid, why not qualify it as such?
Actually, it was the most polite adjective I could come up with...
September 20, 2012 at 8:28 am
Eugene Elutin (9/20/2012)
jcrawf02 (9/20/2012)
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
You should have used a nullable column, and just removed the adjective entirely...
Sorry, but it's not nullable in my database. The remark was stupid, why not qualify it as such?
Actually, it was the most polite adjective I could come up with...
The problem is that the word can be misunderstood between countries.
September 20, 2012 at 10:32 am
Luis Cazares (9/20/2012)
Eugene Elutin (9/20/2012)
jcrawf02 (9/20/2012)
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
You should have used a nullable column, and just removed the adjective entirely...
Sorry, but it's not nullable in my database. The remark was stupid, why not qualify it as such?
Actually, it was the most polite adjective I could come up with...
The problem is that the word can be misunderstood between countries.
Oh! Just that? Sorry, no problem, it is here: http://dictionary.reference.com/browse/stupid 😉
September 20, 2012 at 11:11 am
Eugene Elutin (9/20/2012)
Luis Cazares (9/20/2012)
Eugene Elutin (9/20/2012)
jcrawf02 (9/20/2012)
Eugene Elutin (9/19/2012)
Jeff Moden (9/18/2012)
Eugene Elutin (9/18/2012)
Please ignore this stupid remark!Easy, big guy. You're right but that's something that he would say. 😉
I've spent 5 minutes to choose the word from the list of "wrong", "irrelevant" and "stupid".
Then tossed my lucky three-side coin and got the one...
:hehe:
You should have used a nullable column, and just removed the adjective entirely...
Sorry, but it's not nullable in my database. The remark was stupid, why not qualify it as such?
Actually, it was the most polite adjective I could come up with...
The problem is that the word can be misunderstood between countries.
Oh! Just that? Sorry, no problem, it is here: http://dictionary.reference.com/browse/stupid 😉
What I meant is that it can be considered more aggresive in some parts than in others. But I agree with your point of view.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply