一个SQL查询的菜鸟问题~请指教啊~~~
表名:[news]
字段:news_id,news_title,category
如果有一条数据category存放的内容为1,2,3,4,5,6
为什么下面的SQL语句查询不出数据
select * from [news] where '1 ' in(category) and news_id=2
[解决办法]
select * from [news] where charindex( '1 ',category) > 0 and news_id=2
[解决办法]
--改用charindex
Select * from [news] where CharIndex( ',1, ', ', ' + category + ', ') > 0 and news_id=2
[解决办法]
表名:[news]
字段:news_id,news_title,category
如果有一条数据category存放的内容为1,2,3,4,5,6
为什么下面的SQL语句查询不出数据
select * from [news] where '1 ' in(category) and news_id=2
select * from [news] where ',1, ' in( ', '+category+ ', ') and news_id=2
[解决办法]
select * from [news] where patindex( '%,1,% ', ', '+category+ ', ')> 0 and news_id=2