Question

Can someone please help me with the below script? I to know how to return the value for the calculation 500*@point_rate. I'm getting the following error message

Msg 235, Level 16, State 0, Line 18
Cannot convert a char value to money. The char value has incorrect syntax.

Script:

DECLARE @SCRIPT VARCHAR(4000)
DECLARE @POINT_RATE MONEY
SET @POINT_RATE = 0.05          


SET QUOTED_IDENTIFIER OFF

SET @SCRIPT = "SELECT 500*'"+ @POINT_RATE + "'"

PRINT @SCRIPT
Was it helpful?

Solution

You need to CAST it to VARCHAR.

Something like

DECLARE @SCRIPT VARCHAR(4000)
DECLARE @POINT_RATE MONEY
SET @POINT_RATE = 0.05          


SET QUOTED_IDENTIFIER OFF

SET @SCRIPT = "SELECT 500*"+ CAST(@POINT_RATE AS VARCHAR(10))

PRINT @SCRIPT
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top