Home Forums SQL Server 2008 T-SQL (SS2K8) Problems with IsNumeric and PatIndex when trying to convert string to Int/BigInt RE: Problems with IsNumeric and PatIndex when trying to convert string to Int/BigInt

  • Can you please provide the CREATE TABLE statement of the h table you are referring to, as well as some sample data?

    Edit: A small test to get you started anyway. It's probably because of the extra space in your pattern. Remove the '123 456' row from the @test-2 table and see the difference...

    declare @test-2 table (po_number nvarchar(50))

    insert into @test-2 (po_number)

    values ('123 456'),('not a po'),('123456'),('123-456'),('not a po'),('-123456')

    select

    CASE WHEN PATINDEX('%[^0-9 ]%',po_number) = 0

    THEN Cast(RTrim(LTrim(po_number)) as BigInt)

    ELSE 0

    END

    from @test-2