Cast Function

# Thread: Cast Function

1. Senior Member
Join Date
Dec 1969
Posts
360

## Cast Function

I receive an error on CAST([Price]= &#039;20&#039; as money) can anybody spot what I&#039;m missing?<BR><BR><BR>UPDATE cart_products SET [Code]= &#039;123&#039;, [CatID]= 104, <BR>[SubCatID]= 37, [Name]= &#039;KSU video&#039;, [ProdDescription]= &#039;They&#039;&#039;re goin&#039;&#039; down&#039;, <BR>CAST([Price]= &#039;20&#039; as money), [Cost]= &#039;15&#039;, [Net]= &#039;5&#039;, [ShipCost]= &#039;3&#039;, [ShipCostMulti]= &#039;3&#039;, <BR>[ImageURL1]= &#039;include/images/&#039;, [ImageURL2]= &#039;include/images/&#039;, [StockQTY]= &#039;40&#039;, <BR>[Status]= &#039;YES&#039;, [Taxable]= &#039;Yes&#039;, [SortOrder]= 0 WHERE [ProductID] = 1772 <BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## HUH???

*AFTER* you assign Price=&#039;20&#039; *THEN* you are going to try to cast that result to Money????<BR><BR>WHAT result???<BR><BR>No way.<BR><BR> [Price] = CAST( 20 AS Money )<BR><BR>Why the &#039;...&#039; around 20??? Better to start with a number, since Money is a numerical type. (It should work either way, but why make SLQ work any harder than it needs to?)<BR><BR>And why would you have fields name Cost, Net, ShipCost, and StockQTY that are TEXT fields???? Why aren&#039;t those number of some kind, as well??? Weird.<BR><BR><BR><BR>

3. Member
Join Date
Dec 1969
Posts
64

## RE: Cast Function

I think the syntax is:<BR><BR>CAST([price] As money)<BR><BR>but I have not tested it...I am not sure a length is allowed there.<BR><BR>bizz

4. Senior Member
Join Date
Dec 1969
Posts
360

## Figured it out!!

SQL_UPDATE = SQL_UPDATE & "[Price]= Convert(money,&#039;" & objUpload.Form("txtItemPrice")& "&#039;), "

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Isn't that what I said???

[Price] = CAST( 20 AS Money ) <BR><BR>For this purpose, CAST and CONVERT are essentially interchangeable.<BR><BR>But you still haven&#039;t explained what those apostrophes are doing around numerical values! Even in this case.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•