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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 What is wrong with this stored procedure?

Author  Topic 

meef
Posting Yak Master

113 Posts

Posted - 2011-05-09 : 08:58:54
When trying to run, it says "Conversion failed when converting character string to smalldatetime data type."

ALTER PROCEDURE [dbo].[sp_Fuel_getFuelSurcharge]

@ShippedLo smalldatetime = '10/10/2008',
@ShippedHi smalldatetime = '10/20/2008'

AS
BEGIN

SELECT fscco as [Fuel Tariff], avgfuel as [Average Fuel], eff as [Effective Date],
pct as [Fuel Surcharge], cents as [Cents], monday as [Monday],
CAST(SUBSTRING(eff,1,4) as numeric) as [Year],
CAST(SUBSTRING(eff,5,2) as numeric) as [Month],
CAST(SUBSTRING(eff,7,2) as numeric) as [Day]
FROM fuel
WHERE
monday >= CONVERT(smalldatetime,@ShippedLo,112) AND
monday <= CONVERT(smalldatetime,@ShippedHi,112)

END



RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-05-09 : 09:07:45
WHERE
monday >= CONVERT(varchar(20),@ShippedLo,112) AND
monday <= CONVERT(varchar(20,@ShippedHi,112)

END
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-05-09 : 09:54:11
What datatype in 'monday' in that table?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

meef
Posting Yak Master

113 Posts

Posted - 2011-05-09 : 10:59:53
quote:
Originally posted by GilaMonster

What datatype in 'monday' in that table?

--
Gail Shaw
SQL Server MVP



VARCHAR(50). Rick's suggestions seems to have worked though, the error went away.
Go to Top of Page
   

- Advertisement -