Error converting data type varchar to float
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 weig开发者_运维知识库ht 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
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
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.
精彩评论