February 24, 2013 at 10:23 pm
Hear to find the palindromic words from a sentence. Palindrome is a word reading the same backward as forward.
Example:
Input string --- Hello-Madam-how-are-you-Madam
Output-
Palindromic word
Madam
Madam
February 24, 2013 at 10:44 pm
Try this.
select 'Hello-Madam-how-are-you-Madam' "col1"
into #testString
select Item
from #testString cross apply dbo.DelimitedSplit8k(#testString.col1,'-') split
where item = reverse(item)
It does require DelimitedSplit8k though (easily searched for on the forums)
February 24, 2013 at 10:57 pm
HI thanks for your reply,
but the i am not able to get required output
February 24, 2013 at 11:09 pm
Do you have the string splitter ?
And you really need to post what you are using and any issues rather than "its not working".
Try posting some full ddl, sample data etc.
What i provided is working where i am.
February 25, 2013 at 2:14 am
HI friend thanks alot 🙂 i get the respective out put
CREATE FUNCTION dbo.SplitStringsByComma(@String varchar(8000), @Delimiter char(1))
returns @temptable TABLE (items varchar(8000))
as
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
split function can be Used as
select * from dbo.SplitStringsByComma('Hello-Madam-how-are-you-Madam','-') split where items= REVERSE(items)
But i have one more doubt:
input string is:
'Hello madam, how are you madam'
output:
items
madam
madam
can you help to resolve this
February 25, 2013 at 3:37 am
select * from dbo.SplitStringsByComma('Hello-Madam-how-are-you-Madam','-') split where items= REVERSE(items)
OK so first thing you need to do is change the '-' to a space ' ' and then use your real input string.
The second thing you will need to do will be to strip all punctuation (, ? ! etc)
Im sure there is someone a lot smarter than me who can offer a solution much more elegant than one i can do myself.
Alternatively, you can always give it a go yourself 🙂
February 25, 2013 at 3:44 am
Thanks alot friend 🙂
February 25, 2013 at 7:47 am
I would HIGHLY recommend you read the article suggested with the DelimitedSplit8K function. Once you read that article you will understand why you need to get rid of your loop splitter and replace it with the much faster version. You can also find the article in my signature by following the link about splitting strings.
_______________________________________________________________
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/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply