fattyfatpants
Programmer
I know I posted this yesterday, but I only got 1 response and I can't figure it out...this procedure takes in 4 values for conversion from string data type to smalldatetime (mm/dd/yyyy)...I keep getting the error "Server: Msg 296, Level 16, State 3, Line 0
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
Server: Msg 296, Level 16, State 1, Line 0
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value."
The two fields I am trying to convert are cost.cbiper and periodt.pe...take a look and let me know...thanks!!
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
Server: Msg 296, Level 16, State 1, Line 0
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value."
The two fields I am trying to convert are cost.cbiper and periodt.pe...take a look and let me know...thanks!!
Code:
CREATE PROC dbo.date_range
@beginperiodrange varchar(4), --variable to hold the beginning period range to look in...input value
@endperiodrange varchar(4), --variable to hold the ending period range to look in...input value
@beginbillperiodrange varchar(4), --variable to hold the beginning billing period range to look in...input value
@endbillperiodrange varchar(4) --variable to hold the ending billing period range to look in...input value
AS
DECLARE @yr char(2), --variable to hold a 2 digit year value
@mn char(2), --variable to hold a 2 digit month value
@dy char(2), --variable to hold a day value
@BeginPeriod varchar(10), --variable to hold the concatenated beginning Period value in a short date format (mm/dd/yyyy)
@EndPeriod varchar(10), --variable to hold the concatenated ending period value in a short date format (mm/dd/yyyy)
@BeginBillPer varchar(10), --variable to hold the concatenated beginning Billing Period value in a short date format (mm/dd/yyyy)
@EndBillPer varchar(10) --variable to hold the concatenated ending billing period value in a short date format (mm/dd/yyyy)
set @yr = right(@beginperiodrange, 2)
set @mn = left(@beginperiodrange, 2)
set @dy = '01'
--will concatenate to look like 06/01/2003
set @BeginPeriod = @mn + '/' + @dy + '/' + '20' + @yr
set @yr = right(@endperiodrange, 2)
set @mn = left(@endperiodrange, 2)
set @dy = '30'
--will concatenate to look like 04/30/2004
set @EndPeriod = @mn + '/' + @dy + '/' + '20' + @yr
set @yr = right(@beginbillperiodrange, 2)
set @mn = left(@beginbillperiodrange, 2)
set @dy = '01'
--will concatenate to look like 06/01/2003
set @BeginBillPer = @mn + '/' + @dy + '/' + '20' + @yr
set @yr = right(@endbillperiodrange, 2)
set @mn = left(@endbillperiodrange, 2)
set @dy = '30'
--will concatenate to look like 04/30/2003
set @EndBillPer = @mn + '/' + @dy + '/' + '20' + @yr
--the fields in the query these are being evaluated against are cost.cbiper (Billing Period) and periodt.pe (Period)
SELECT client.claddr1, matter.mmatter, matter.morgaty, client.crelated, matter.mjnum, cost.cbiper, periodt.pe, periodt.peendt, cost.camount, cost.cbillamt, matths.mhdobidb, matths.mhdowkdb
FROM son_db.dbo.periodt periodt INNER JOIN (((son_db.dbo.client client INNER JOIN son_db.dbo.matter matter ON client.clnum=matter.mclient) INNER JOIN son_db.dbo.matths matths
ON matter.mmatter=matths.mhmatter) INNER JOIN son_db.dbo.cost cost ON matter.mmatter=cost.cmatter) ON periodt.pe=matths.mhper
WHERE [b]convert(smalldatetime, cost.cbiper) BETWEEN cast(@BeginBillPer as smalldatetime) AND cast(@EndBillPer as smalldatetime) AND convert(smalldatetime, periodt.pe) BETWEEN cast(@BeginPeriod as smalldatetime) AND cast(@EndPeriod as smalldatetime)[/b]
AND matter.mjnum<>'' AND matter.mmatter NOT LIKE '10000%'
ORDER BY matter.morgaty, client.crelated, matter.mmatter, periodt.peendt