October 22, 2009 at 9:18 am
Hi All,
I have a requirement to select from a source which is giving me data in a cloumn like this
ab.cd.ef.gh.kl
hh.jj.kk.rr.ee.bb
ff.gg.tt
Now, I have to select only the values that comes in between 2 dots (removing dots)
:
for this given data,the result should be like this:
cdefgh
jjkkrree
gg
There can be any number of dots in the complete string.
I am not able to find a solution for this.
Any help on this.
Any help is appreciated.
Thanks a lot
Thanks [/font]
October 22, 2009 at 9:59 am
So the requirement is to remove all the dots and remove the left 2 chars and the right 2 chars?
Would you like it in SQL or in script?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 22, 2009 at 10:26 am
SELECT REPLACE('ab.cd.ef.gh.kl','.','')
SELECT REPLACE('hh.jj.kk.rr.ee.bb','.','')
Result:
(No column name)(No column name)
abcdefghklhhjjkkrreebb
October 22, 2009 at 10:30 am
Thanks,
I got the replace to remove dots but how do I remove the first and last characters...
SELECT REPLACE('ab.cd.ef.gh.kl','.','')
SELECT REPLACE('hh.jj.kk.rr.ee.bb','.','')
Result:
(No column name) (No column name)
abcdefghkl hhjjkkrreebb
Result should be:
(No column name) (No column name)
cdefgh jjkkrree
i want only charactr between 2 dots....
And it can be any number of charascters (not just 2)
I can also have a.b.c.d.f.g
Thanks
Thanks [/font]
October 22, 2009 at 10:31 am
@Phil,
Yes, but it is not just 2 characters, it can be in any number...
ex:
w.e.r.t
ff.g.h.tr
thanks
Thanks [/font]
October 22, 2009 at 10:34 am
SELECT SUBSTRING(REPLACE('ab.cd.ef.gh.kl','.',''), 3, len(REPLACE('ab.cd.ef.gh.kl','.',''))-4)
SELECT SUBSTRING(REPLACE('hh.jj.kk.rr.ee.bb','.',''), 3, len(REPLACE('hh.jj.kk.rr.ee.bb','.',''))-4)
You didn't remove the left and right 2 characters 🙂
--edit aaah, just seen the latest post - that's tougher
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 22, 2009 at 10:51 am
October 22, 2009 at 11:03 am
Beat me to it Phil.
Here's what I came up with.
DECLARE @Input varchar(8000)
SELECT @Input = 'ab.cd.ef.gh.kl'
DECLARE @Start int
SELECT @Start = CHARINDEX('.', @Input) + 1
DECLARE @End int
SELECT @End = LEN(@Input) - CHARINDEX('.', REVERSE(@Input)) - @Start + 1
SELECT REPLACE(SUBSTRING(@Input, @Start, @End), '.', '')
October 22, 2009 at 11:03 am
Thanks a lot... Phil..Erik
it works....... 😎
I have one more question,
Is there any way to split this long string into columns partitioned by DOTS
For Ex:
ab.cd.ef.gh
gives
Col1 Col2 Col3 Col4
ab cd ef gh
Thanks
Thanks [/font]
October 22, 2009 at 11:09 am
Erik Kutzler (10/22/2009)
Beat me to it Phil.<snip>
Same logic ... must be good! 🙂
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 22, 2009 at 11:10 am
SQL Learner-684602 (10/22/2009)
Thanks a lot... Phil..Erikit works....... 😎
I have one more question,
Is there any way to split this long string into columns partitioned by DOTS
For Ex:
ab.cd.ef.gh
gives
Col1 Col2 Col3 Col4
ab cd ef gh
Thanks
Sure. Define '.' as the column delimiter and let SSIS do all the splitting work for you.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 22, 2009 at 11:20 am
Ohkk..Yes but I am using a Stored Procedure and have to do it in a select query...
Thanks [/font]
October 22, 2009 at 12:29 pm
SQL Learner-684602 (10/22/2009)
Ohkk..Yes but I am using a Stored Procedure and have to do it in a select query...
Once again, this topic does not belong in the SSIS section. In the future please post your questions in the correct forum sections. Doing so should results in better answers.
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]
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply