Solved

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

Posted on 2009-05-14
5
1,667 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
  • 3
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Use (no points please):

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

Author Comment

by:H-SC
Comment Utility
acperkins,

Perfect!!!
0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
many many thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now