• 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.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St