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
Solved

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

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

840 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