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!

SQL Server Data type problem. Syntax error...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Here is my error copied out of the Event Viewer.

ErrDescription : [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting
the varchar value '<FACIL_PMT_TYPES><PMT_TYP_CD>' to a column of data type smallint. :

And my SP:

CREATE PROCEDURE sp_GetAvailablePaymentTypeInfoAsXML
@Payment_Types_XML varchar(1000) OUTPUT
AS
Declare @PaymentTypeCode smallint
Declare @PaymentTypeDescription varchar(50)
Declare PaymentTypes_Cursor CURSOR For

select PMT_TYP_CD, PMT_TYP_DESC from REPR_FACIL_PMT_TYP

Open PaymentTypes_Cursor
FETCH NEXT FROM PaymentTypes_Cursor Into @PaymentTypeCode, @PaymentTypeDescription

SET @Payment_Types_XML = &quot;<FACIL_PMT_TYPES>&quot;

WHILE @@FETCH_STATUS = 0
BEGIN
SET @Payment_Types_XML = @Payment_Types_XML + &quot;<PMT_TYP_CD>&quot; + @PaymentTypeCode + &quot;</PMT_TYP_CD>&quot; + &quot;<PMT_TYP_DESC>&quot; + @PaymentTypeDescription + &quot;</PMT_TYP_DESC>&quot;
FETCH NEXT FROM PaymentTypes_Cursor Into @PaymentTypeCode, @PaymentTypeDescription
END

SET @Payment_Types_XML = @Payment_Types_XML + &quot;</FACIL_PMT_TYPES>&quot;

Close PaymentTypes_Cursor
Deallocate PaymentTypes_Cursor
 
Looks like @PaymentTypeCode is the problem.
Change:

SET @Payment_Types_XML = @Payment_Types_XML + &quot;<PMT_TYP_CD>&quot; + @PaymentTypeCode + &quot;</PMT_TYP_CD>&quot; + &quot;<PMT_TYP_DESC>&quot; + @PaymentTypeDescription + &quot;</PMT_TYP_DESC>&quot;

to:

SET @Payment_Types_XML = @Payment_Types_XML + &quot;<PMT_TYP_CD>&quot;
+ convert(varchar(12), @PaymentTypeCode)+ &quot;</PMT_TYP_CD>&quot; + &quot;<PMT_TYP_DESC>&quot;
+ @PaymentTypeDescription
+ &quot;</PMT_TYP_DESC>&quot;
 
Can you not assign (concat) a small int or other data type to a string like that?
 
In this situation implicit conversion is not performed. In other circumstances such as passing a smallint variable to a stored procedure integer parameter, implicit conversion is performed. Take a look at &quot;Data Type Conversion&quot; in the BOL.

Also you can use either CONVERT or CAST.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top