| Author |
Topic |
|
kvkanth008
Starting Member
1 Post |
Posted - 2009-02-26 : 07:52:10
|
| 01 VarunK Sr_Test_Engineer02 Raghu Sr_Quality_Control_Enginr03 Auditya Sr_Quality_Analyst_Engr.04 Prabhakar Test_Engineer05 Hari Test_Engineer06 CVRSwamy Test_Engineer07 Tirumalesh Test_EngineerIn the above table, I would like to fetch records that have only one under score(_). How can I do this, Pls Help me out.Kolvi |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-26 : 08:02:56
|
does this work ?select * from <yourtable>where len(col)-charindex('_',reverse(col))+1=charindex('_',col)replace <yourtable> with your table name, and col with the column name. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-02 : 04:56:31
|
| orwhere len(col)-len(replace(col,'_',''))=1MadhivananFailing to plan is Planning to fail |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-02 : 07:16:01
|
| Hi try this one alsodeclare @temp table (id int, name varchar(32), desig varchar(32))insert into @tempselect 01 ,'VarunK', 'Sr_Test_Engineer' union allselect 02 ,'Raghu', 'Sr_Quality_Control_Enginr' union allselect 03 ,'Auditya', 'Sr_Quality_Analyst_Engr' union allselect 04 ,'Prabhakar', 'Test_Engineer' union allselect 05 ,'Hari', 'Test_Engineer' union allselect 06 ,'CVRSwamy' ,'Test_Engineer' union all select 07 ,'Tirumalesh' ,'Test_Engineer' select * from @temp where parsename(replace(desig,'_','.'),3) is null |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-02 : 08:01:31
|
quote: Originally posted by Nageswar9 Hi try this one alsodeclare @temp table (id int, name varchar(32), desig varchar(32))insert into @tempselect 01 ,'VarunK', 'Sr_Test_Engineer' union allselect 02 ,'Raghu', 'Sr_Quality_Control_Enginr' union allselect 03 ,'Auditya', 'Sr_Quality_Analyst_Engr' union allselect 04 ,'Prabhakar', 'Test_Engineer' union allselect 05 ,'Hari', 'Test_Engineer' union allselect 06 ,'CVRSwamy' ,'Test_Engineer' union all select 07 ,'Tirumalesh' ,'Test_Engineer' select * from @temp where parsename(replace(desig,'_','.'),3) is null
Wont work for all set of datadeclare @temp table (id int, name varchar(32), desig varchar(32))insert into @tempselect 01 ,'VarunK', 'Sr_Test_Engineer' union allselect 02 ,'Raghu', 'Sr_Quality_Control_Enginr' union allselect 03 ,'Auditya', 'Sr_Quality_Analyst_Engr' union allselect 04 ,'Prabhakar', 'Test_Engineer' union allselect 05 ,'Hari', 'Test_Engineer' union allselect 06 ,'CVRSwamy' ,'Test_Engineer' union all select 07 ,'Tirumalesh' ,'Test_Engineer_Test_Engineer_' select * from @temp where parsename(replace(desig,'_','.'),3) is null MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|