Solved

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

Posted on 2009-05-14
5
1,690 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 500 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

688 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