如何从此
中删除前导零number RESULT WOULD BE LIKE THIS
00000.9 .9
A0001.1 A1.1
G0101.3 G101.3
00808.8 808.8
J0000.5 J.5
答案 0 :(得分:0)
declare @input varchar(10);
declare @output varchar(10);
set @input = '00000.9';
while ((ISNUMERIC(substring(@input,1,1)) = 0) or (substring(@input,1,1) = '0'))
begin
if substring(@input,1,1) = '0'
begin
set @input = substring(@input,2,len(@input) )
end
else
if ISNUMERIC(substring(@input,1,1)) = 0
begin
set @output = substring(@input,1,1);
set @input = substring(@input,2,len(@input))
end
end
if LEN(@output) > 0
set @input = @output + @input
select @input
@input是您的输入
答案 1 :(得分:0)
ALTER FUNCTION NUMBER(@NUMBER VARCHAR(7))
RETURNS VARCHAR(7) AS
BEGIN
DECLARE @NUM VARCHAR(1)
DECLARE @ NUM1 VARCHAR(7)
SET @ NUM = SUBSTRING(@ NUMBER,1,1)
IF(@NUM LIKE'[A-Z%]')
BEGIN
SET @NUM1=@NUM+''+CAST(CONVERT(FLOAT,SUBSTRING(@NUMBER,2,7),2)AS VARCHAR(7))
END
ELSE
BEGIN
SET @NUM1=LTRIM(STR(cast(@NUMBER as float),case when len(cast(@NUMBER as float)) > 7 then 7 else len(cast(@NUMBER as float)) end,1))
END
RETURN @NUM END