?
Solved

Cannot convert a char value to money. The char value has incorrect syntax.

Posted on 2009-05-14
5
Medium Priority
?
1,701 Views
Last Modified: 2012-06-27
I have a sp that sends out email and works great.  But today I added a database column to the sp called q1fine that has a set datatype of money on the server, but when I incorporate the column into the sp, I get an error of the following...

Cannot convert a char value to money. The char value has incorrect syntax.

here is the sp..

Any ideas would be very much appreciated!


declare
@Email varchar(100),
@body varchar(max),
@q1 varchar(100),
@q1qty varchar(8),
@q1fine money,
DECLARE  CursorTemplate CURSOR
FAST_FORWARD FOR       
select email,q1,q1qty,q1fine
FROM my_view
OPEN CursorTemplate
FETCH NEXT FROM CursorTemplate
INTO      @Email,@q1,@q1qty,@q1fine
WHILE (@@FETCH_STATUS = 0)
BEGIN

Set @body =
'<html>' + case when @q1 like '%*%' then '<font color="red">' + @q1 + ' ** ' + @q1qty + ' ' + 'Total - ' + @q1fine + '</font>' else @q1 end + '<br>' +'</html>'
0
Comment
Question by:H-SC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24386663
You should convert the Money datatype to varchar before adding it to the string


Set @body =
'' + case when @q1 like '%*%' then '' + @q1 + ' ** ' + @q1qty + ' ' + 'Total - ' +CAST( @q1fine  as  varchar(20)  )  + '' else @q1 end + '
' +''
0
 
LVL 1

Author Comment

by:H-SC
ID: 24387371
aneeshattingal,

I think that I am on the right path using your suggestion....When I do that, It shows the cents and that is ok but does not show the comma

what I am getting now is 2500.00
I would like to get 2,500.00

any ideas
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24387407
Use (no points please):

CONVERT(varchar(20), @q1fine, 1)
0
 
LVL 1

Author Comment

by:H-SC
ID: 24388549
acperkins,

Perfect!!!
0
 
LVL 1

Author Comment

by:H-SC
ID: 24388556
many many thanks
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question