You must Sign In to post a response.
  • Category: SQL Server

    How to check numeric value in sql?


    Are you looking for way to check a value is numeric or not? Read this thread to get help.



    Here is my code. I want only numeric character.If it is other than numeric, should not print.
    Here @msg is substring of one of string,which dynamically created.So I can not change type of @msg to int.It can be ',,3' or '4,,,',etc.Sometime @msg contain comma,so I want to check for numeric.Isnumeric() consider comma as numeric.I gives 1 as result.How to handle it?

    Declare @msg varchar(5)
    set @msg = ',5'
    if(isnumeric(@msg) = 1)
    begin
    print 'Numeric'
    logic
    end
  • #740706
    Try this..

    Declare @msg varchar(5)
    set @msg = ',5'
    if(isnumeric(@msg) = 1)
    begin
    print 'Numeric'
    print REPLACE(@msg,',','')
    end

    Regards,
    Manick

  • #740710
    Declare @msg varchar(5)
    set @msg = ',5'
    if( @value not LIKE '%[^0-9]%')
    begin
    print 'Numeric'
    -- logic
    end

    It work properly.Does anybody tell me meaning of it.I think Meaning is : msg type should not contain other than 0-9.

  • #740712
    Hi,
    My simple question here is why you are doing this kind of validation is in SQL query. This should be handled in your front end whatever you use. Handling this in SQL query will not help and it is not the standard practice.


    Regards,
    Asheej T K

  • #740713
    Declare @msg varchar(5)
    set @msg = ',5'
    if( @value not LIKE '%[^0-9]%')
    begin
    print 'Numeric'
    -- logic
    end

    It work properly.Does anybody tell me meaning of it.I think Meaning is : msg type should not contain other than 0-9.

  • #740715
    Hi Pinky !
    You can use SELECT * FROM Tablename WHERE NOT Col1 LIKE '%[^0-9]%' for check numeric value in sql

  • #740716
    Declare @msg varchar(5)
    set @msg = ',5'
    if( @value not LIKE '%[^0-9]%')
    begin
    print 'Numeric'
    -- logic
    end

    It work properly.Does anybody tell me meaning of it.I think Meaning is : msg type should not contain other than 0-9.


  • Sign In to post your comments