Convert negative varchar value to negative numeric

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

  • 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 16 (of 16 total)

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