2

I have the following SQL statement which is giving me this error.

"Error converting data type varchar to float" in this line

   ,  pe.ProductWeight + ' lb' AS weight

I realize this is wrong but I don't know how to add "lb" to the weight value. Any help would be appreciated.

SELECT p.ProductCode AS id

,  p.ProductName AS title

,  'Home & Garden > Household Appliance Accessories > Laundry Appliance Accessories' AS product_type

,  IsNull(pe.SalePrice,pe.ProductPrice) AS price

,  IsNull(pe.ProductManufacturer,'n/a') AS brand

,  IsNull(pe.ProductCondition,'new') AS condition

,  CONVERT(VARCHAR(10), (GETDATE() + 30),120) AS expiration_date

,  pd.ProductDescriptionShort AS [stripHTML-description]

,  'http://www.thesite.com/v/vspfiles/photos/' + IsNull(p.Vendor_PartNo,p.ProductCode) + '-2.jpg' AS image_link

,  'http://www.thesite.asp?ProductCode=' + p.ProductCode + '&Click=1327'  AS link

,  pe.ProductWeight + ' lb' AS weight


FROM Products p

INNER JOIN Products_Descriptions pd ON p.ProductID = pd.ProductID

INNER JOIN Products_Extended pe ON pd.ProductID = pe.ProductID

WHERE (p.IsChildOfProductCode is NULL OR p.IsChildOfProductCode = ' AND (p.HideProduct is NULL OR p.HideProduct <> 'Y')

AND (pe.ProductPrice > 0)

ORDER BY p.ProductCode

2 Answers 2

4

If you want to concatenate a float and a string, you need to cast the float to a string first:

   CAST(pe.ProductWeight AS VARCHAR(20)) + ' lb' AS weight
1
  • LOL, seems pretty easy. Thx 20 would be the max length, correct?
    – user357034
    Sep 10, 2011 at 15:12
1

Varchar has lower precedence than float, so it is attempting to turn ' lb' into a float and failing.

See http://msdn.microsoft.com/en-us/library/ms190309.aspx for ranking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.