What does ''%[^0-9]%'' mean?

  • I would be grateful if someone would please explain what the following code actually means. I'm a software developer with 3 weeks experience. I'm learning to write Stored Procs for SQL Server 2000 at my new job. I was about to write an isInteger function, but I found a script here on sqlservercentral.com, called isInteger, submitted by AFPeterson. I tested the code, it works like a charm, but how?

    It appears to contain a regular expression, but I had the impression that Transact-SQL had no support for regex. If it does, would someone please point me to some tutorials/resources/articles? I haven't been able to find anything other than 3rd party plugins. I used regex a couple of times in Perl, and love the power it offers.

    Anyway, what does  '%[^0-9]%' mean?

    CODE:

    BEGIN

     DECLARE @bitReturn bit

     IF @strToBeEval LIKE '%[^0-9]%'

        SET @bitReturn = 0

     ELSE

        SET @bitReturn = 1

     RETURN @bitReturn

    END

    PS- I could really use a killer transact-sql book. Any recommendations?

     

    Thanks in advance,

    Greg Norris - CoLinear Systems

     

  • If you search for LIKE in books online you'll see a description of each piece of this.

    In a nutshell it is saying if any characters in the string are not 0 - 9 then

    return false or 0.

    The way it breaks down is this.

    % = Multi-character wildcard

    ^ = Not operator

    [0-9] = range of numbers 0 through 9

    Hope this helps

  • Hey Mark,

    Yes, that helps a lot! I really appreciate the info. Is there anything I need to click on to give you a vote, or to otherwise show gratitude? I don't see anything here, but some forums have such a thing.

    Thanks again,

    Greg

     

  • Greg,

    Sending a short reply as you did is a great way to show appreciation.

    Glad I could help.

    Mark

     

  • I tried it your way, and all I get is the following error:

    Could not find stored procedure 'UPDATE SYSOENT

                           SET CREDIT_CARD_# = dbo.udf_smearcc(@column),

                           WHERE order_no < 100'.

     

    I did it like you said. Here's my code:

    DECLARE @table CHAR(8), @column VARCHAR(16)

    SET @table  = @tableName

    SET @column = @colName

    SET @sqlString = N'UPDATE ' + @table + '

                           SET ' + @column + ' = dbo.udf_smearcc(@column),

                           WHERE order_no < 100' --For testing

    EXEC @sqlString

     

    Any suggestions?

  • Greg,

    I'm confused.  This post doesn't seem to correspond to the rest of the thread.  In any event, try putting parens around @sqlString...

    EXEC (@sqlString)

    Steve

Viewing 6 posts - 1 through 5 (of 5 total)

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