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.
Author |
Topic |
SQLNoob81
Starting Member
38 Posts |
Posted - 2013-03-18 : 09:47:51
|
Hi AllI would like to know how to query a field in a table with comma separated input.e.gInputString = 'Math, Geography, History'select * from Scholars where subjects = InputStringneed to know how to match all and another query to match at least one |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-03-18 : 10:07:06
|
If this (InputString = 'Math, Geography, History' )format is fixed and also small set of values, then useWHERE ', ' + @InputString + ', ' LIKE '%, ' + subjects + ', %'Note:fixed format in the sense value1, value2, valu3--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
SQLNoob81
Starting Member
38 Posts |
Posted - 2013-03-19 : 06:13:38
|
Maybe I did not explain myself correctly.The field (Subjects) would Typically hold text as follows:Joe Soap took the following Subjects at School, Math, although he was not good at it. History, Avg Student but was very good at geography.I will have a Text box on a form where you can enter Subject that can be searched. eg. "History, Math, Geography" |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-03-19 : 06:41:20
|
May be try this...WHERE subjects LIKE '%' + REPLACE(@InputString, ', ', '%')+ '%'--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-19 : 10:03:49
|
quote: Originally posted by bandi May be try this...WHERE subjects LIKE '%' + REPLACE(@InputString, ', ', '%')+ '%'--Chandu
Hmm..what if the order of subjects are different in string ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|