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 |
|
yoko
Starting Member
3 Posts |
Posted - 2005-08-30 : 10:38:45
|
I'm new to T-SQL and the prior DBA wrote a Sproc that prints a report in(Crystal Report V10). The logic is incorrect for the current month and Fiscal Year( it begins July 1). The Headers should read: Actual August 2005 - ACtual August 2004 (Comparison with last Year) and Actual Agust 2005 & Budget August 2005 (Comparison with this year's Budget). The code is:CREATE Procedure WeeklySalesReportasdeclare @thisMonth integer, @thisYear integer, @fiscalYear intdeclare @testDate dateTimeselect @testDate = getDate()--select @testDate = '07/04/05'select @thisMonth = datepart(month, @testDate) -1select @thisYear = datepart(year, @testDate)select @fiscalYear = @thisYearif( @thisMonth >= 7 ) select @fiscalYear = @fiscalYear+1declare @startDate datetime, @endDate dateTimeselect @endDate = endDate from harvardclub.dbo.fiscalMonths where monthInfo = @thisMonth and fiscalYear = @fiscalYearselect @startDate = startDate from harvardclub.dbo.fiscalMonths where monthInfo = @thisMonth and fiscalYear = @fiscalYear I have changed it many times - with no results. Any ideas/suggestions will be greatly appreciated.thanks |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-30 : 13:41:56
|
Hi Yoko,If I understand you question(s) there's 2 of them. Question one is, given a fiscal year start of July 1, Provide code to calculate the fiscal month and year for any given date. Will this work for you?--it begins July 1declare @thisMonth integer, @thisYear integer, @fiscalYear intdeclare @testDate dateTimeselect @testDate = getDate()--select @testDate = '7/04/05'select @thisMonth = m + case when m < 7 then 6 else -6 end ,@thisYear = y + case when m > 6 then 1 else 0 endfrom ( select datepart(month, @testDate) m ,datepart(year, @testDate) y ) aselect @testDate ActualDate ,@thisMonth fiscalMonth ,@thisYear fiscalYear Question two has something to do with report headers? You provided no code or table structures that return report header information so I'm afraid you'll have to provide more information about that. See this link about posting questions that will get answered fast:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxBe One with the OptimizerTG |
 |
|
|
yoko
Starting Member
3 Posts |
Posted - 2005-08-30 : 15:11:21
|
| Sorry for not making myself clear. here is the complete SPROC that runs every month:>> SET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO/* 11/04/03 Notes: 1) Added Fiscal Month 2) Determine which fiscal month this is*/CREATE Procedure WeeklySalesReportasdeclare @thisMonth integer, @thisYear integer, @fiscalYear intdeclare @testDate dateTimeselect @testDate = getDate()--select @testDate = '07/04/05'select @thisMonth = datepart(month, @testDate) -1select @thisYear = datepart(year, @testDate)select @fiscalYear = @thisYearif( @thisMonth >= 7 ) select @fiscalYear = @fiscalYear+1declare @startDate datetime, @endDate dateTimeselect @endDate = endDate from harvardclub.dbo.fiscalMonths where monthInfo = @thisMonth and fiscalYear = @fiscalYearselect @startDate = startDate from harvardclub.dbo.fiscalMonths where monthInfo = @thisMonth and fiscalYear = @fiscalYear--select @testDate, @startDate start, @endDate enddate, @fiscalyear, @thisMOnthselect sum( totalRoomAmount) as RoomSales, sum( RoomsAvailable ) as RoomsAvailable , sum( totalInUse ) as RoomsOccupied, sum( totalPeople ) as NumberOfPersons, sum( GuestCount ) as NumberOfGuestRooms, datePart( dw, reportdate ) as daynum , FiscalMonth, convert(varchar(4), fiscalYear ) as fiscalYear from dailystatswhere reportDate between @startDate and @endDategroup by datepart( dw, reportDate ), fiscalmonth, fiscalyearorder by datepart( dw, reportDate )GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO <<The SPROC is used in Crystal Reports V 10 & looks like: COMPARISON WITH LAST YEAR -------------------------- ACTUAL ACTUAL AUGUST AUGUST 2005 2005rOOM SALES $300,000 $200,000ROOMS AVAIL 2,000 2,085ROOMS OCCUP 1,000 1,100 ETC comparison with this years'budget -------------------------------- ACTUAL ACTUAL AUGUST AUGUST 2005 2005rOOM SALES $300,000 $200,000ROOMS AVAIL 2,000 2,085ROOMS OCCUP 1,000 1,100 ETC.. I'm trying to get the SPROC to calculate the Current Month & year (each month) without re-writing. i.e. August, 2005; September 2005 etc.thanks for your help. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-30 : 16:25:21
|
>>Sorry for not making myself clearStill not too clear Is this what you're looking for?:declare @testDate dateTimeselect @testDate = getDate()select datename(month, @testDate) + ', ' + datename(year, @testDate) Be One with the OptimizerTG |
 |
|
|
|
|
|
|
|