Author |
Topic |
j0shua
Starting Member
40 Posts |
Posted - 2008-11-10 : 04:12:09
|
Is there a function that would select a specific part of a data such as0011-black0213-yellow0214-yellow/greeni want to select only the black, yellow, and yellow/greenI only know how to select a specific part like the first 4 characters.Thank you. i will appreciate your help. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 04:15:43
|
[code]SELECT PARSENAME(REPLACE(Col,'-','.'),1) FROM Table[/code] |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-10 : 04:31:08
|
pls try this too select right(col,charindex('-',col)+1) from tableok |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2008-11-10 : 04:34:01
|
SELECT SUBSTRING('0213-yellow',CHARINDEX('-','0213-yellow',1)+1,LEN('0213-yellow')) |
|
|
j0shua
Starting Member
40 Posts |
Posted - 2008-11-10 : 04:35:40
|
Wow, thank you so much!!! |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-11-10 : 04:36:24
|
[code]Hi sooraj, u r query ll not give correct resulttry like thisDeclare @t Table(Val Varchar(100))Insert Into @tSelect '0011-black' union allSelect '0213-yellow' union allSelect '0214-yellow/green'Select *, right(Val, Len(Val) - charindex('-',Val))From @t[/code][code]"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"[/code] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 04:41:39
|
quote: Originally posted by soorajtnpki pls try this too select right(col,charindex('-',col)+1) from tableok
it should be select right(col,len(col)-charindex('-',col)) from table |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-10 : 04:44:59
|
ok but have a look at this declare @chr varchar(30)set @chr='sdf-fdgdg'select right(@chr,charindex('-',@chr)+1)will give fdgdgwats the problem?ok |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-10 : 04:50:44
|
quote: Originally posted by soorajtnpki ok but have a look at this declare @chr varchar(30)set @chr='sdf-fdgdg'select right(@chr,charindex('-',@chr)+1)will give fdgdgwats the problem?ok
See heredeclare @chr varchar(30)set @chr='TEST-TESTING'select right(@chr,charindex('-',@chr)+1)MadhivananFailing to plan is Planning to fail |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-10 : 05:28:29
|
thanks madhivanan for ur help.. also thanks peternero for pointing my fault.. |
|
|
|