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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implicit conversion not allowed in Stored Proc

Status
Not open for further replies.

ashaig

Programmer
Apr 9, 2001
26
GB
I'm getting the following error which (I think) objects to using the 'sweight' parm in the stored proc. I can't work out how I would use the CONVERT function as all given examples are for SELECT statements not qualifying statements:

"Microsoft OLE DB Provider for SQL Server (0x80040E14)
Implicit conversion from data type nvarchar to money is not allowed. Use the CONVERT function to run this query."

The script is as follows:
sweight = parseFloat(tempWt);

if (sHWkey > 0)
{
loRS = Server.CreateObject("ADODB.Recordset");
loRS.Open("Exec GetRates " + sCountry + "," + sweight + "," + sHWkey ,sdbConnString);

The Stored Procedure is:

CREATE PROCEDURE [GetRates]
(@country text, @weight money, @HWkey int)
AS
SELECT PForce.grade1,PForce.grade2,PForce.grade3,PForce.grade4,PForce.grade5,PForce.grade6, Grades.grade

FROM PForce INNER JOIN
Zones ON PForce.Zone = Zones.Zone INNER JOIN
Grades ON Zones.Zone =Grades.Zone
WHERE (Zones.country like @country) and (PForce.weight = @weight) and (Grades.HWKey = @HWKey)


 
declare @weight to be a decimal value, then convert it in the stored procedure. For example -

Code:
CREATE PROCEDURE [GetRates] 
(@country text, @weight decimal(10,2), @HWkey int)
AS

etc.

(PForce.weight = CONVERT(money, @weight) 

etc.


It seems odd that the values of a variable named sweight are monetary? Of course computers don't mind what you call your money.

And why would you use a TEXT datatype to store the name of a country? @country VARCHAR(50) should do.

While we're at it, I think you are going to need some parentheses and single quote marks in this statement -

Code:
"Exec GetRates('" + sCountry + "', " + sweight + "," + sHWkey + ")"
 
Thanks for the response,

my difficulty was a lot to do with an embarrassing misunderstanding of precision/scale, which I discovered after posting. Suffice to say I'm using decimal now, and all is well. I'll have a look at the text/quotes meantime, although the code now seems to be working OK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top