Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Posted on 2008-10-16
Medium Priority
1,244 Views
Hi Guys

i have this query

this gives me the nextquarter invoice date.
Now my problem is that sum customers needs to be charged every half year. How do i calculate that? it doesnt seem like datediff has a half year function?
0
Question by:tim_carter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 143

Expert Comment

ID: 22729660
half year = 6 months or 2 quarters ...
so, where is the problem?
0

LVL 6

Accepted Solution

openshac earned 2000 total points
ID: 22729702
Try the following:

Of course you may need to pull the value 2 or 6 from another column in your query.

You could have a column called CustomerChargedEveryNQuarters which has values 1 or 2
``````
DateAdd(q, 2 * DATEDIFF(q, t2.StartDate,getdate()),t2.StartDate) NextInvoiceQuarter

or

DateAdd(m, 6 * DATEDIFF(m, t2.StartDate,getdate()), t2.StartDate) NextInvoiceQuarter

or even

DateAdd(q, CustomerChargedEveryNQuarters  * DATEDIFF(q, t2.StartDate,getdate()), t2.StartDate) NextInvoiceQuarter
``````
0

LVL 1

Author Comment

ID: 22729823
Thanks guys

works perfectly
0

LVL 1

Author Comment

ID: 22730522
Guys it doesnt work right

declare @StartTime datetime
set @StartTime = '10/01/2008'

SELECT
CASE t2.HowToCharge
END
NextInvoiceDate,

Am i missing something here. The half year doesnt work.

If i set @StartTime = 10/01/2008 And the date in the StartDate is 10/01/2008. NextInvoiceDate, will be 10/01/2008 as it should. But as this should be every half year, the next date should be 04/01/2009 RIGHT? but it isnt, if you change StartTime to 04/01/2009 NextInvoiceDate will be 10/01/2009. But if you change StartTime to 03/01/2009 NextInvoiceDate will be 04/01/2009. What am i doing wrong?

0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll