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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Searching for Concatenated Values In Cols...

Author  Topic 

ramdas
Posting Yak Master

181 Posts

Posted - 2009-06-01 : 14:40:13
Hi,
I have a table which has a filed called GrpName. The values are like

GrpID GrpName
1 A,B,C
2 B,C
3 B

When the user passes the selection as 'B,C'to the stored procedure, I want the rows 1,2,3 to be returned as the result set. How would i achieve this. When I used the Like statement i got back only GrpID 2 back. Any thoughts on this...
Thank you

Ramdas Narayanan
SQL Server DBA

vishal.gadhia@gmail.com
Starting Member

4 Posts

Posted - 2009-06-01 : 16:25:55
Hi Ramdas:
SELECT
Grpid,
GrpName
FROM
Group
WHERE
GrpName LIKE '%[B,C]%'

This query shall give your ur desired results as well as it even if you change the character from 'B,C' to 'A,B', it shall still return the whole set of values.
I hope this helps.
Thanks
Vishal Gadhia
Aspiring DBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-02 : 13:04:59
you should certainly read about normalisation
Go to Top of Page
   

- Advertisement -