DECLARE
@BankAccount
TABLE
(AccNo
VARCHAR
(15))
INSERT
SELECT
'01010'
'0010200'
'000103000'
*
FROM
--Methods to remove leading zeros
-- 1.) converting to integer data type
CONVERT
(
INT
,AccNo) AccNo
@BankAccount -- NN - note, this method will only work if the data are clean
-- 2.) using SUBSTRING
SUBSTRING
(AccNo,PATINDEX(
'%[^0]%'
,AccNo),LEN(AccNo)) AccNo
-- 3.) using REPLACE,LTRIM & RTRIM
REPLACE
(LTRIM(
(AccNo,
'0'
,
' '
)),
) AccNo
--To remove both leading & trailing zeros
(RTRIM(LTRIM(
))),
@BankAccount See also relevant thread This entry participates in the TechNet Guru contributions for June contest. See also : http://social.technet.microsoft.com/wiki/contents/articles/17785.sql-server-query-language-transact-sql.aspx
Naomi N edited Revision 6. Comment: Added link to a thread
Naomi N edited Revision 5. Comment: Changed casing in the title
Naomi N edited Revision 4. Comment: Added link to Guru contributions
Peter Geelen - MSFT edited Revision 2. Comment: Fixed color codes to names
Naomi N edited Original. Comment: Grammar
Thank you, it solved my problem,
Just for somebody if playing with float,
First convert it to String using STR TSQL function then follow this article