7 Replies - 697 Views - Last Post: 13 April 2009 - 10:29 AM Rate Topic: -----

#1 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Is the syntax wrong?

Post icon  Posted 06 April 2009 - 07:46 PM

I've followed the instructions of a text book and when I tried to execute the following script I got a message saying: 'Cannot convert a char value to money. The char value has incorrect syntax.'

DECLARE @dataType VARCHAR(10)
SET @dataType = '58.00'
UPDATE ProductDetails.Products
	SET CostPrice = @dataType
WHERE ProductCode = 'S502S'


Any helpful advice would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Is the syntax wrong?

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Is the syntax wrong?

Posted 06 April 2009 - 07:47 PM

It would be helpful to know which Database this is to be used for.
Was This Post Helpful? 0
  • +
  • -

#3 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Re: Is the syntax wrong?

Posted 06 April 2009 - 07:52 PM

View Postno2pencil, on 7 Apr, 2009 - 01:47 AM, said:

It would be helpful to know which Database this is to be used for.

MS Sql Server 2008 Express, and I'm not deliberately attempting to enter a wrong data type. The figure '58.00' is to be inserted into a column containing the money data type.
Was This Post Helpful? 0
  • +
  • -

#4 F!st!cuffs  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 153
  • Joined: 15-July 08

Re: Is the syntax wrong?

Posted 06 April 2009 - 07:54 PM

It needs to be of the same data type to enter it in. Change varchar to whatever type CostPrice is.
Was This Post Helpful? 0
  • +
  • -

#5 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Re: Is the syntax wrong?

Posted 06 April 2009 - 08:47 PM

View PostF!st!cuffs, on 7 Apr, 2009 - 01:54 AM, said:

It needs to be of the same data type to enter it in. Change varchar to whatever type CostPrice is.

Still getting the same message...I changed varchar to money, which is the data type of CostPrice.
Thank you for your input.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Is the syntax wrong?

Posted 06 April 2009 - 09:25 PM

So the following code is giving you the error?

DECLARE @dataType MONEY
SET @dataType = $58.00
UPDATE ProductDetails.Products
	SET CostPrice = @dataType
WHERE ProductCode = 'S502S'


Was This Post Helpful? 0
  • +
  • -

#7 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Re: Is the syntax wrong?

Posted 06 April 2009 - 09:37 PM

View PostPsychoCoder, on 7 Apr, 2009 - 03:25 AM, said:

So the following code is giving you the error?

DECLARE @dataType MONEY
SET @dataType = $58.00
UPDATE ProductDetails.Products
	SET CostPrice = @dataType
WHERE ProductCode = 'S502S'


Yep, any ideas why? Would greatly appreciate your advice. The same message appears...even by using the dollar sign.
Was This Post Helpful? 0
  • +
  • -

#8 kzimmerm  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 70
  • Joined: 08-February 09

Re: Is the syntax wrong?

Posted 13 April 2009 - 10:29 AM

View Postsam.adams61, on 6 Apr, 2009 - 08:37 PM, said:

View PostPsychoCoder, on 7 Apr, 2009 - 03:25 AM, said:

So the following code is giving you the error?

DECLARE @dataType MONEY
SET @dataType = $58.00
UPDATE ProductDetails.Products
	SET CostPrice = @dataType
WHERE ProductCode = 'S502S'


Yep, any ideas why? Would greatly appreciate your advice. The same message appears...even by using the dollar sign.


The problem is the dollar sign in the SET statement. It should read

SET @dataType = 58.00



The MONEY data type handles the penny rounding which is unique to money and not NUMERIC or FLOAT.

Hope this helps.
Kurt
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1