• Luis Cazares (7/30/2012)


    You can use it to check if 2 phrases are palindromes.

    Just kidding.

    create function IsPalindrome(@String1 varchar(100), @String2 varchar(100))

    returns table

    return

    (

    select Case when @String1 = REVERSE(@String2) then 1 else 0 end as IsPalindrome

    )

    go

    with cte (string1, string2)

    as

    (

    Select 'racecar', 'racecar' union all

    select 'racetruck', 'racetruck'

    )

    select *

    from cte

    cross apply dbo.IsPalindrome(string1, string2)

    😀

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/