Convert negative varchar value to negative numeric

  • Toby Harman

    SSCarpal Tunnel

    Points: 4128

    Nice use of REPLACE... shoulda thought of that!

  • Patrick Dadey

    Grasshopper

    Points: 11

    For SQL Server 2012 onwards simplest solution is to use TRY_PARSE.

    DECLARE @NegativeNumeric varchar(100);

    SET @NegativeNumeric='50.10-';

    SELECT "Value" = TRY_PARSE(@NegativeNumeric AS DECIMAL(10,2));

Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply