I need to convert a value 5.300000000 to 0005300. Basically I want to remove the decimal point, pad the out put with a couple of zeros and return a value that is 7 bytes long. I may need to convert something like 10.300000000 to be 0010300.
Anyone have any thoughts?
Thanks.DECLARE @.x decimal(5,2)
SELECT @.x = 5.3
SELECT @.x, RIGHT(REPLICATE('0',7)+REPLACE(CONVERT(varchar(7), @.x * 10),'.',''),7)|||Hi,
Here is a little code that should do it for you.
Granted it is ugly but it works
declare @.d decimal (16,9)
set @.d = 9.3000
print Replicate('0', 7 - len ( replace( Left(@.d,Charindex('.',Cast(@.d as Varchar))+3),'.','')))+ replace(Left(@.d,Charindex('.',Cast(@.d as varchar))+3),'.','')
Hope that Helps
Tal McMahon|||I have a function for zero-padding, which cleans things up a bit in my queries:
CREATE FUNCTION [dbo].[fn_zero_pad]
(@.string_data VARCHAR(100),
@.new_length INT)
RETURNS VARCHAR(100) AS
BEGIN
RETURN REPLICATE('0', @.new_length - LEN(@.string_data)) + @.string_data
END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment