lefeal lefeal - 1 year ago 74
SQL Question

fixing sql data EG 000-575.33

I was given a few thousand records of varchars such as the one above. They all need to be 10 characters, and I guess they just indiscriminately padded zeros on them. How can I move the negative sign over to the left so


Answer Source

Something like this should do. If they aren't already padded correctly let us know and we can stuff those.

declare @v varchar(64) = '000-575.33'
        when CHARINDEX('-',@v) > 1 then '-' + replace(@v,'-','')
        else @v
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download