我試圖轉換一些decimals
到varchar
,但他們得到四捨五入。爲什麼這個Sql Server CAST(..)將Decimal舍入到VarChar?
有人能告訴我爲什麼嗎?
declare @UpperLeftLatitude DECIMAL,
@UpperLeftLongitude DECIMAL,
@BottomRightLatitude DECIMAL,
@BottomRightLongitude DECIMAL
SET @UpperLeftLatitude = 38.663
SET @UpperLeftLongitude = -122.857
SET @BottomRightLatitude = 37.795
SET @BottomRightLongitude = -121.219
DECLARE @SearchRectangleString VARCHAR(MAX);
SET @SearchRectangleString = 'POLYGON((' + CONVERT(VARCHAR(50), @UpperLeftLatitude) + ' ' + CAST(@UpperLeftLongitude AS VARCHAR(50)) + ','
+ CAST(@BottomRightLatitude AS VARCHAR(50)) + ' ' + CAST(@UpperLeftLongitude AS VARCHAR(50)) + ','
+ CAST(@BottomRightLatitude AS VARCHAR(50)) + ' ' + CAST(@BottomRightLongitude AS VARCHAR(50)) + ','
+ CAST(@UpperLeftLatitude AS VARCHAR(50)) + ' ' + CAST(@BottomRightLongitude AS VARCHAR(50)) + ','
+ CAST(@UpperLeftLatitude AS VARCHAR(50)) + ' ' + CAST(@UpperLeftLongitude AS VARCHAR(50)) + '))';
SELECT @SearchRectangleString
-------------------
POLYGON((39 -123,38 -123,38 -121,39 -121,39 -123))
(1 row(s) affected)
注:是的,我知道我的緯度/多頭周圍走錯了路。我會盡快切換。
遠遠地抱-發芽。我想在經歷了15年的Sql之後,我會選擇那個shiz。該回家了。腦中的單個腦細胞非常疲倦。謝了哥們! – 2010-07-28 07:46:40