Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detrermining whether invoice date is within current financial year

Status
Not open for further replies.

thebigcheese

Technical User
Mar 19, 2001
10
CH
I have a sales transaction database (SQL Server 2K) with invoices all having an invoice date. Our Financial Year runs 1 October YYYY thru 30 September YYYY+1.

I have the following code for Oracle DB, but seek assistance in modifying this for SQL Server.

Code is:

TABLE_NAME.INVOICE_DATE >=  to_Date('01/07/' || DECODE (sign(7-to_char(sysdate, 'MM')),1,to_char(sysdate, 'YYYY') - 1,to_char(sysdate, 'YYYY')),'DD/MM/YYYY')   and TABLE_NAME.INVOICE_DATE <= sysdate
 
Previous Financial Year    This assumes a Financial Year of 1/7 to 30/6
 
TABLE_NAME.INVOICE_DATE between  to_Date('01/07/' || DECODE (sign(7-to_char(sysdate, 'MM')),1,to_char(sysdate, 'YYYY') - 2,to_char(sysdate, 'YYYY')-1),'DD/MM/YYYY')   and  to_Date('30/06/' || DECODE (sign(7-to_char(sysdate, 'MM')),1,to_char(sysdate, 'YYYY') - 1,to_char(sysdate, 'YYYY')),'DD/MM/YYYY')

Please Help !!

 
I haven't worked out exactly the dates you need but something like this should do it.

Code:
SELECT CONVERT(DATETIME, '01-Oct-' +
	 CASE 
		WHEN MONTH(GETDATE()) < 10 
			THEN CONVERT(VARCHAR(4),YEAR(GETDATE()) - 1)
		ELSE CONVERT(VARCHAR(4),YEAR(GETDATE()))
		END)
Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top