Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select from csv column

Author  Topic 

soniyakapoor03
Starting Member

11 Posts

Posted - 2010-05-17 : 04:00:18
Hi,

I have some doubts in sql select.

I need to select fname from the table where ID is 2.

My table structure is like this

Fname, ID(nvarchar(30))

kpn 2
jkm 3
mgr 2,3
krr 5


I need to select only columns having ID is 2


final result should be

Fname

kpn
mgr

I tried with split function. but not working


Please help.

Thanks

soniya

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-17 : 04:15:16
If you are using SQL Server 2005 ?

select t.Fname
from yourtable t
cross apply dbo.CSVTable(t.ID) i
where i.numberval = 2



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-17 : 11:43:58
[code]
select t.Fname
from yourtable t
WHERE ',' + t.ID + ',' LIKE '%,2,%'
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -