SQL SERVER RegEx Question

  • I have been trying to get this condition to be TRUE, but can't seem to get it right.

    Any suggestions would be helpful. Thanks.

    DECLARE @stopat datetime

    SET @stopat = '2015-06-23 02:16'

    IF @stopat LIKE '[1-2][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][^0-9a-z][0-9][0-9]:[0-9][0-9]'

    PRINT 'TRUE'

    ELSE PRINT 'FALSE'

  • fpchavula (6/25/2015)


    I have been trying to get this condition to be TRUE, but can't seem to get it right.

    Any suggestions would be helpful. Thanks.

    DECLARE @stopat datetime

    SET @stopat = '2015-06-23 02:16'

    IF @stopat LIKE '[1-2][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][^0-9a-z][0-9][0-9]:[0-9][0-9]'

    PRINT 'TRUE'

    ELSE PRINT 'FALSE'

    TRY:

    DECLARE @stopat datetime

    SET @stopat = '2015-06-23 02:16'

    IF CONVERT(VARCHAR(16), @stopat, 120) LIKE '[1-2][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]:[0-9][0-9]' PRINT 'TRUE'

    ELSE PRINT 'FALSE'

    Try SELECT @stopat and you'll see why it was not matching.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I see the cause, thank you very much for your help.

Viewing 3 posts - 1 through 3 (of 3 total)

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