Why is this Sql Server CAST(..) rounding a Decimal to a VarChar? -


I'm trying to change some decimals to varchar , But they are getting rounded .

Can anyone tell me why?

  declared @UpperLeftLatitude decimal, @UpperLeftLongitude decimal, @BottomRightLatitude decimal, @BottomRightLongitude decimal set @UpperLeftLatitude = 38.663 set @upperLeftLongitude = -122.857 set @BottomRightLatitude = 37.795 set @BottomRightLongitude = -121 .219 Declaration @SearchRectangleStringVARCHAR (Max); Set @SearchRectangleString = 'Polygon (VARCHAR (50), @UpperLeftLatitude) +' + Cast (@UpperLeftLongitude as VARCHAR (50) +) ',' + Cast (@BottomRightLatitude as VARCHAR (set) 50)) + '' + (+) as 'UpwardLeftLongitude VARCHAR +', '+' Cast (@ VARCHAR (50)) as 'BottomRightLatitude +' (@BottomRightLongitude as VARCHAR) Varchar (50) as Cast ++, '+ Cast (@ UpperLeftLatitude) +' 'Cast + (@BottomRightLongitude as VARCHAR) (+ 50) +', '+ Cast (@UpperLeftLatitude) )) + '' + Cast (@UpperLeftLongitude as VARCHAR (50)) + '))'; SELECT @SearchRectangleString ------------------- Polygon ((39 -12338-12338-121,39-121,39-123)) (1 line ( S) Affected)  

Note: Yes, I know that my waves are wrong or wrong I will change them soon.

This is because your decimal is not specified with length. They are not storing any decimal places

Try:

  @test decimal declaration @ test2 decimal (8.4) @test set = 12.3456 set @ test2 = 12.3456 SELECT @test, @ test2  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -