• dwain.c (10/20/2013)


    sqlserver12345 (10/20/2013)


    I do not want to use reverse function.please check the code I posted and correct what wrong I did.thanks

    That's exactly what we're doing by showing you the right way! Assuming this is homework, you should be challenging your instructor by delivering outstanding results.

    Easy if you happen to have a pattern-based string splitter in your toolbox.

    WITH SampleData (palindrome) AS

    (

    SELECT 'Madam I''m Adam'

    UNION ALL SELECT 'ABC'

    UNION ALL SELECT 'ABBA'

    UNION ALL SELECT 'A man, a plan, a canal - Panama!'

    UNION ALL SELECT 'Madam in Eden, I''m Adam'

    UNION ALL SELECT 'Doc, note: I dissent. A fast never prevents a fatness. I diet on cod'

    UNION ALL SELECT 'Never odd or even'

    ),

    SplitStrings AS

    (

    SELECT palindrome

    ,RemovePuncuation=

    (

    SELECT Item + ''

    FROM SampleData b

    CROSS APPLY dbo.PatternSplitCM(palindrome, '[A-Za-z]')

    WHERE a.palindrome = b.palindrome AND [Matched] = 1

    ORDER BY ItemNumber

    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'

    )

    FROM SampleData a

    )

    SELECT palindrome

    ,IsPalindrome=CASE WHEN REVERSE(RemovePuncuation) = RemovePuncuation THEN 1 ELSE 0 END

    FROM SplitStrings;

    The PatternSplitCM FUNCTION can be found in the fourth link in my signature.

    The problem is, you used REVERSE which the OP said he couldn't do. Heh... you also forget that a Palindrome can contain numeric digits. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)