Author |
Topic |
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2009-01-30 : 10:08:34
|
hi i have a field which is a token string the data is in following formati7*809*......so on7*4567*.........so on 809 and 4567 are customer ids . So my question is i want to show just those numbers but sometimes the customer number is 3 integers and sometimes 4 .How can i get that.Thaks in advance |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-30 : 10:21:47
|
are you using sql 2005? |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-01-30 : 10:26:27
|
Something like this in SQL 2000.declare @tab as table(InputString varchar(50))insert into @tabselect '7*809*erfujd*dckvchd'union select '7*4567*73484*edfhdjfh'select convert(int,SUBSTRING(InputString,3,PATINDEX('%*%',SUBSTRING(InputString,3,LEN(InputString)))-1)) from @tab |
|
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2009-01-30 : 10:44:46
|
Hi Rick but its not just the just examples i gave ...there are countless tokenstringsquote: Originally posted by RickD Something like this in SQL 2000.declare @tab as table(InputString varchar(50))insert into @tabselect '7*809*erfujd*dckvchd'union select '7*4567*73484*edfhdjfh'select convert(int,SUBSTRING(InputString,3,PATINDEX('%*%',SUBSTRING(InputString,3,LEN(InputString)))-1)) from @tab
|
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-01-30 : 10:47:14
|
So change InputString to your field and @tab to your table and work with what I have given you, I can only work with the samples you provide. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-30 : 11:59:58
|
is it that you'll have multiple customerids coming in each column value? |
|
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2009-01-30 : 17:55:07
|
quote: Originally posted by visakh16 is it that you'll have multiple customerids coming in each column value?
the table design is like thiscustomer id, customer_token1 7*345*hdfhdkkdfjkd2 7*3458*494jekrjkejrker3 7*123*HFHDKHFDFHKDFSO ON...WHAT IS NEED IS FROM THE CUSTOMER_TOKEN FIELD NUMBERS THAT ARE AFTER 7. I.E 345 ,3458,123 SO ON |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-01-31 : 00:15:14
|
try thisdeclare @temp table ( customerid int, customer_token varchar(8000))insert into @tempselect 1, '7*345*hdfhdkkdfjkd' union allselect 2, '7*3458*494jekrjkejrker' union allselect 3,'7*123*HFHDKHFDFHKDF' select customerid, substring(substring(customer_token,charindex('*',customer_token)+1,len(customer_token)),1,charindex('*',substring(customer_token,charindex('*',customer_token)+1,len(customer_token)))-1) as customer_tokenfrom @temp |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-31 : 01:06:30
|
Search for function fnParseStrind and/or fnParseList here on SQLTeam. E 12°55'05.63"N 56°04'39.26" |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-31 : 01:14:43
|
[code]declare @temp table ( customerid int, customer_token varchar(8000))insert into @tempselect 1, '7*345*hdfhdkkdfjkd' union allselect 2, '7*3458*494jekrjkejrker' union allselect 3,'7*123*HFHDKHFDFHKDF' union allselect 4, '*12121212121*asdfasdfdasf'select substring(customer_token,charindex('*',customer_token)+1,charindex('*',customer_token,charindex('*',customer_token)+1)-(charindex('*',customer_token)+1)) from @tempJai Krishna[/code] |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-01-31 : 01:50:56
|
Try this alsodeclare @temp table ( customerid int, customer_token varchar(8000))insert into @tempselect 1, '7*345*hdfhdkkdfjkd' union allselect 2, '7*3458*494jekrjkejrker' union allselect 3,'7*123*HFHDKHFDFHKDF' declare @temp1 table ( customerid int,a varchar(32))insert into @temp1select customerid, substring(customer_token,charindex('*',customer_token)+1,len(customer_token)) from @tempselect customerid,substring(a,1,charindex('*',a)-1) as token from @temp1 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-01-31 : 02:10:50
|
Try this alsodeclare @temp table ( customerid int, customer_token varchar(8000))insert into @tempselect 1, '7*345*hdfhdkkdfjkd' union allselect 2, '7*3458*494jekrjkejrker' union allselect 3,'7*657*HFHDKHFDFHKDF' union allselect 4,'7*768*HFHDKHFDFHKDF' union allselect 5,'7*678*HFHDKHFDFHKDF' select parsename(replace(customer_token,'*','.'),2) from @temp |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|