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 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-11-08 : 08:15:19
|
| Hi,I have a table field lets say field1 (varchar) which has a value like 1,4,11,13 (data range for this field is 1 to 14)The query i want to use is like below;SELECT field3 FROM table1 WHERE field2='abc' AND IsApproved= '1' AND field1 LIKE %'1'% AND '11.09.2010 00:00:00' BETWEEN start AND endThe problem is when the value in the query field1 is 1, it also gets data for 11 and 13. But i want to get only data for 1.Any help would be great.Thanks in advance.Best Regards |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-11-08 : 08:17:35
|
| Normalize your data. DO NOT put comma separated data in a column. Problem solved.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 08:19:51
|
AND ','+field1+',' LIKE %',1,'% But it is a bad practice to have CSV values in a column... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-11-08 : 08:27:16
|
| Incorrect syntax near ',1,' |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-08 : 08:42:42
|
That was a copy and paste from your post...Try this:AND ','+field1+',' LIKE '%,1,%' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-11-09 : 01:36:13
|
| thanks so much |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-11-09 : 03:00:28
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|