显示标签为“fiscal”的博文。显示所有博文
显示标签为“fiscal”的博文。显示所有博文

2012年3月9日星期五

Fiscal year search

Hi

I am trying to perform a search that will return records based on a
fiscal year search of the bill_Date. The user gives the year then I
want to search based on the fiscal year (July 1 - June 30) for the year
given. The table looks like this

Bill Table
id_Num bill_date bill_amount
23 7/1/2005 500.00
33 12/2/2005 600.00
44 3/3/2006 700.00

I have tried

Select Bill.id_num, Bill.bill_date, Bill.bill_amount
from Bill
where Bill.bill_date BETWEEN 7/1/ + @.year and 6/30/ + (@.year +1)

Plus a variety of other fruitless concoctions...but nothing seems to
work. Any help would be appreciated.Discovered answer on my own. Thanks anyway.

Twobridge wrote:

Quote:

Originally Posted by

Hi
>
I am trying to perform a search that will return records based on a
fiscal year search of the bill_Date. The user gives the year then I
want to search based on the fiscal year (July 1 - June 30) for the year
given. The table looks like this
>
Bill Table
id_Num bill_date bill_amount
23 7/1/2005 500.00
33 12/2/2005 600.00
44 3/3/2006 700.00
>
I have tried
>
Select Bill.id_num, Bill.bill_date, Bill.bill_amount
from Bill
where Bill.bill_date BETWEEN 7/1/ + @.year and 6/30/ + (@.year +1)
>
Plus a variety of other fruitless concoctions...but nothing seems to
work. Any help would be appreciated.

|||I've got a simlar problem - can you post your solution?
Dan

On Nov 29, 1:50 am, "Twobridge" <Twobri...@.gmail.comwrote:

Quote:

Originally Posted by

Discovered answer on my own. Thanks anyway.
>
>
>
Twobridge wrote:

Quote:

Originally Posted by

Hi


>

Quote:

Originally Posted by

I am trying to perform a search that will return records based on a
fiscal year search of the bill_Date. The user gives the year then I
want to search based on the fiscal year (July 1 - June 30) for the year
given. The table looks like this


>

Quote:

Originally Posted by

Bill Table
id_Num bill_date bill_amount
23 7/1/2005 500.00
33 12/2/2005 600.00
44 3/3/2006 700.00


>

Quote:

Originally Posted by

I have tried


>

Quote:

Originally Posted by

Select Bill.id_num, Bill.bill_date, Bill.bill_amount
from Bill
where Bill.bill_date BETWEEN 7/1/ + @.year and 6/30/ + (@.year +1)


>

Quote:

Originally Posted by

Plus a variety of other fruitless concoctions...but nothing seems to
work. Any help would be appreciated.- Hide quoted text -- Show quoted text -

|||On 29 Nov 2006 01:28:49 -0800, Dan wrote:

Quote:

Originally Posted by

>I've got a simlar problem - can you post your solution?
>Dan


Hi Dan,

The best way to solve this is to have a calendar table (see
http://sqlserver2000.databases.aspf...dar-table.html),
with FiscalYear as one of it's columns.

Second best is to build a date in string format, using a format that is
guaranteed to be unabiguous WRT the order of day and month: yyyymmdd.
For isntance, for a fiscal year that starts on july first:

DECLARE @.FiscalYear int
SET @.FiscalYear = 2006
SELECT something
FROM sometable
WHERE TheDate >= CAST(@.Year AS varchar) + '0701'
AND TheDate < CAST(@.Year + 1 AS varchar) + '0701'

You might want to read this as well:
http://www.karaszi.com/SQLServer/info_datetime.asp
--
Hugo Kornelis, SQL Server MVP|||Hi Hugo

Thanks - i'll take a look

Dan
On Nov 30, 9:13 pm, Hugo Kornelis
<h...@.perFact.REMOVETHIS.info.INVALIDwrote:

Quote:

Originally Posted by

On 29 Nov 2006 01:28:49 -0800, Dan wrote:
>

Quote:

Originally Posted by

I've got a simlar problem - can you post your solution?
DanHi Dan,


>
The best way to solve this is to have a calendar table (seehttp://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using...),
with FiscalYear as one of it's columns.
>
Second best is to build a date in string format, using a format that is
guaranteed to be unabiguous WRT the order of day and month: yyyymmdd.
For isntance, for a fiscal year that starts on july first:
>
DECLARE @.FiscalYear int
SET @.FiscalYear = 2006
SELECT something
FROM sometable
WHERE TheDate >= CAST(@.Year AS varchar) + '0701'
AND TheDate < CAST(@.Year + 1 AS varchar) + '0701'
>
You might want to read this as well:http://www.karaszi.com/SQLServer/info_datetime.asp
>
--
Hugo Kornelis, SQL Server MVP

Fiscal or Calendar Year Function error

Hello,
I am trying to create a function that returns the first day of the fiscal or
calendar year depending on the parameter supplied. However, I get the
error: Error 443: Invalid use of the 'getdate' within a function.
Any help would be appreciated.
Thanks in advance, sck10
CREATE FUNCTION dbo.fn_GetCalendarFiscalYear (@.YearType varchar(100))
RETURNS varchar(255)
AS
BEGIN
Declare @.strCalendarFiscal varchar(255)
SELECT @.strCalendarFiscal =
CASE
WHEN @.YearType = 'calendar' Then '1/1/' + Convert(varchar(255),
year(getdate()))
WHEN @.YearType = 'fiscal' Then
CASE
WHEN month(getdate()) BETWEEN 10 AND 12 THEN
'10/1/' + Convert(varchar(255), year(getdate()))
ELSE
'10/1/' + Convert(varchar(255), year(getdate()) - 1)
END
ELSE 'Pick "calendar" or "fiscal"'
END AS 'strFiscalYearStart'
RETURN @.strCalendarFiscal
Hi,
Welcome to use MSDN Managed Newsgroup!
I am so sorry that you can not put a function that returns a varible
result in a user defined function. Check MVP Aaron Bertrand's article for
this issue
How do I use GETDATE() within a User-Defined Function (UDF)?
http://www.aspfaq.com/2439
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.

Fiscal or Calendar Year Function error

Hello,
I am trying to create a function that returns the first day of the fiscal or
calendar year depending on the parameter supplied. However, I get the
error: Error 443: Invalid use of the 'getdate' within a function.
Any help would be appreciated.
Thanks in advance, sck10
CREATE FUNCTION dbo.fn_GetCalendarFiscalYear (@.YearType varchar(100))
RETURNS varchar(255)
AS
BEGIN
Declare @.strCalendarFiscal varchar(255)
SELECT @.strCalendarFiscal = CASE
WHEN @.YearType = 'calendar' Then '1/1/' + Convert(varchar(255),
year(getdate()))
WHEN @.YearType = 'fiscal' Then
CASE
WHEN month(getdate()) BETWEEN 10 AND 12 THEN
'10/1/' + Convert(varchar(255), year(getdate()))
ELSE
'10/1/' + Convert(varchar(255), year(getdate()) - 1)
END
ELSE 'Pick "calendar" or "fiscal"'
END AS 'strFiscalYearStart'
RETURN @.strCalendarFiscalHi,
Welcome to use MSDN Managed Newsgroup!
I am so sorry that you can not put a function that returns a varible
result in a user defined function. Check MVP Aaron Bertrand's article for
this issue
How do I use GETDATE() within a User-Defined Function (UDF)?
http://www.aspfaq.com/2439
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Fiscal or Calendar Year Function error

Hello,
I am trying to create a function that returns the first day of the fiscal or
calendar year depending on the parameter supplied. However, I get the
error: Error 443: Invalid use of the 'getdate' within a function.
Any help would be appreciated.
Thanks in advance, sck10
CREATE FUNCTION dbo.fn_GetCalendarFiscalYear (@.YearType varchar(100))
RETURNS varchar(255)
AS
BEGIN
Declare @.strCalendarFiscal varchar(255)
SELECT @.strCalendarFiscal =
CASE
WHEN @.YearType = 'calendar' Then '1/1/' + Convert(varchar(255),
year(getdate()))
WHEN @.YearType = 'fiscal' Then
CASE
WHEN month(getdate()) BETWEEN 10 AND 12 THEN
'10/1/' + Convert(varchar(255), year(getdate()))
ELSE
'10/1/' + Convert(varchar(255), year(getdate()) - 1)
END
ELSE 'Pick "calendar" or "fiscal"'
END AS 'strFiscalYearStart'
RETURN @.strCalendarFiscalHi,
Welcome to use MSDN Managed Newsgroup!
I am so sorry that you can not put a function that returns a varible
result in a user defined function. Check MVP Aaron Bertrand's article for
this issue
How do I use GETDATE() within a User-Defined Function (UDF)?
http://www.aspfaq.com/2439
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

2012年3月7日星期三

Fiscal Month Date Range: 22 thru 21

I'm looking for a script to do the following?
I need to have a date range for each month of the year from the 22nd of each
month to the 21st of the next.
This doesn't work... as it starts at the first, I need it to start at the 22
of
the previous month.
declare @.date datetime
set @.date = '1/1/2005'
select case when datepart(mm,@.date) = 1 and datepart(dd,@.date) between 1 and
21
then 1 else 0 end
TIA
JeffP...Considered a calendar table to mark fiscal months?
http://www.aspfaq.com/2519
"JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
news:ewMNyExBGHA.1288@.TK2MSFTNGP09.phx.gbl...
> I'm looking for a script to do the following?
> I need to have a date range for each month of the year from the 22nd of
> each
> month to the 21st of the next.
> This doesn't work... as it starts at the first, I need it to start at the
> 22 of
> the previous month.
> declare @.date datetime
> set @.date = '1/1/2005'
> select case when datepart(mm,@.date) = 1 and datepart(dd,@.date) between 1
> and 21
> then 1 else 0 end
>
> TIA
> JeffP...
>|||The calendar table is an excellent solution. If you do not want to do
that, you could use a Case statement for your solution. This example
assumes your fiscal year starts on December 22.
select <all other columns>,
case when datepart(day,datefield) <= 21
then cast(year(datefield) as varchar(4)) + ' ' + right('0' +
cast(month(datefield) as varchar(2)),2)
when datepart(day,datefield > 21 and month(datefield) = 12 then
cast(year(datefield) + 1 as varchar(4)) + ' 01'
else cast(year(datefield) as varchar(4)) + ' ' + right('0' +
cast(month(datefield) + 1 as varchar(2)),2)
else date(mm,datefield) + 1 end)
as FiscalMonth|||Oops - don't forget the END to the Case statement ;-)|||All, Thanks...
Thanks, one the one hand the case stmt works well for a quick & dirty query,
but
I'm like'ing the table, that way if anything changes in the rules I can crea
te
an interfact to the cal table and make adjustments.
TIA
JeffP....
"Gary Gibbs" <ggibbs@.aahs.org> wrote in message
news:1135271277.811769.38450@.g49g2000cwa.googlegroups.com...
> Oops - don't forget the END to the Case statement ;-)
>|||Here is another way. Probably a bit faster then using table lookups if you
call it a lot.
declare @.mthStart datetime
declare @.mthEnd datetime
declare @.i int
set @.mthStart = '1/22/2005'
set @.mthEnd = dateadd(day, 30, @.mthStart)
set @.i = 1;
while (@.i <= 12)
begin
select @.mthStart, @.mthEnd
set @.mthStart = dateadd(month, 1, @.mthStart)
set @.mthEnd = dateadd(month, 1, @.mthEnd)
set @.i = @.i + 1
end
William Stacey [MVP]
"JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
news:%23bXcyTyBGHA.3984@.TK2MSFTNGP14.phx.gbl...
> All, Thanks...
> Thanks, one the one hand the case stmt works well for a quick & dirty
> query, but
> I'm like'ing the table, that way if anything changes in the rules I can
> create
> an interfact to the cal table and make adjustments.
> TIA
> JeffP....
> "Gary Gibbs" <ggibbs@.aahs.org> wrote in message
> news:1135271277.811769.38450@.g49g2000cwa.googlegroups.com...
>|||Thanks to all who posted...
This is nearly perfect... All the links were helpful as I have other client
s
with different date range issues.
create table #view_paid (datepaid varchar(10) ,polchoice varchar(2))
insert #view_paid
select '01/03/2005' ,10
insert #view_paid
select '01/13/2005' ,10
insert #view_paid
select '01/23/2005' ,10
insert #view_paid
select '01/31/2005' ,10
insert #view_paid
select '02/03/2005' ,10
insert #view_paid
select '02/13/2005' ,10
insert #view_paid
select '02/23/2005' ,10
declare @.mthStart datetime ,@.mthEnd datetime
set @.mthStart = '1/22/2005'
set @.mthEnd = dateadd(day, 30, @.mthStart)
select datepaid ,polchoice
,dateadd(ms,-3,dateadd(mm,datediff(mm,0,dateadd(mm,-1,datepaid)),0)+22)
Period_Start
,dateadd(mm,datediff(mm,0,datepaid),0)+2
1 Period_End
,Jan = case when datepaid between dateadd(mm,-1,@.mthStart) and
dateadd(mm,-1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
,Feb = case when datepaid between dateadd(mm,0,@.mthStart) and
dateadd(mm,0,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
,Mar = case when datepaid between dateadd(mm,1,@.mthStart) and
dateadd(mm,1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
from #view_paid with(nolock)
where cast(datepaid as datetime) between '01/01/2005' and '03/27/2005'
order by datepaid
select [Year] = datepart(yy,datepaid)
,JanTotals =sum( case when datepaid between dateadd(mm,-1,@.mthStart) and
dateadd(mm,-1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
,FebTotals = sum(case when datepaid between dateadd(mm,0,@.mthStart) and
dateadd(mm,0,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
,MarTotals = sum(case when datepaid between dateadd(mm,1,@.mthStart) and
dateadd(mm,1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
from #view_paid with(nolock)
where cast(datepaid as datetime) between '01/01/2005' and '03/27/2005'
group by datepart(yy,datepaid)
drop table #view_paid
JeffP....
"William Stacey [MVP]" <william.stacey@.gmail.com> wrote in message
news:ud17lO0BGHA.3600@.TK2MSFTNGP10.phx.gbl...
> Here is another way. Probably a bit faster then using table lookups if yo
u
> call it a lot.
> declare @.mthStart datetime
> declare @.mthEnd datetime
> declare @.i int
> set @.mthStart = '1/22/2005'
> set @.mthEnd = dateadd(day, 30, @.mthStart)
> set @.i = 1;
> while (@.i <= 12)
> begin
> select @.mthStart, @.mthEnd
> set @.mthStart = dateadd(month, 1, @.mthStart)
> set @.mthEnd = dateadd(month, 1, @.mthEnd)
> set @.i = @.i + 1
> end
> --
> William Stacey [MVP]
> "JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
> news:%23bXcyTyBGHA.3984@.TK2MSFTNGP14.phx.gbl...
>