July 19, 2011 at 12:10 am
I am Having a Table called SampleData
Create table SampleData
(
id int,
value1 varchar(MAX),
value2 varchar(MAX),
value3 varchar(MAX)
)
IN this above table i am storing the string values which are comma separated.
Insert into SampleData
select 1,'aaa,bbb,cccc','bbbb,cccc','' union all
select 2,'','cccc,jjjj','ddd,ffff' union all
select 3,'aaa,bbb','bbb,ccc','ddd,eee'
Results:-
1aaa,bbb,ccccbbbb,cccc
2cccc,jjjjddd,ffff
3aaa,bbbbbb,cccddd,eee
Now I am Querying this table
Declare @temp varchar(max)
set @temp = 'aaa'
now i am checking with this @temp String in SampleData Table
Query is
select * from SampleData where @temp in (value1)
it is giving the exact match, what i am passing to the local variable..
i need the results like
combinations of string what i passed in the @temp variable...
Thanks in Advance
July 19, 2011 at 1:21 am
with slobby data, you will need a slobby method to process it.
there are a number of split functions to be found at SSC.
e.g. http://www.sqlservercentral.com/articles/Tally+Table/72993/
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
July 19, 2011 at 2:12 pm
Expect scans:
DECLARE @temp VARCHAR(MAX)
SET @temp = 'aaa'
SELECT *
FROM SampleData
WHERE ',' + value1 + ',' LIKE '%,' + @temp + ',%'
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply