求一sql语句,急!请大虾帮忙!
一个表:
有id,h_add字段,h_add是字符型,
存了像这样的数据
2
3
2,3
3,4
我现在想从表中查出h_add列中等于","前的数据或者等于","后的数据,用一个sql能不能实现?
问题点数:20、回复次数:7Top
1 楼itblog(Just for wife!)回复于 2006-06-02 10:47:26 得分 15
例:
select * from 表名 where charindex(',2,',','+h_add+',')>0Top
2 楼libin_ftsafe(子陌红尘(TS for Banking Card))回复于 2006-06-02 10:47:54 得分 3
declare @t table(code varchar(10))
insert into @t select '2'
insert into @t select '3'
insert into @t select '2,3'
insert into @t select '3,4'
declare @code varchar(10)
set @code='2'
select * from @t where charindex(','+@code+',',','+code+',')>0Top
3 楼libin_ftsafe(子陌红尘(TS for Banking Card))回复于 2006-06-02 10:48:36 得分 0
declare @t table(code varchar(10))
insert into @t select '2'
insert into @t select '3'
insert into @t select '2,3'
insert into @t select '3,4'
declare @code varchar(10)
set @code='2'
select * from @t where charindex(','+@code+',',','+code+',')>0
/*
code
----------
2
2,3
*/Top
4 楼godfather_wang()回复于 2006-06-02 10:49:58 得分 2
select left('3,4',charindex(',','3,4',len('3,4')-2)-1)
select substring('3,4',charindex(',','3,4')+1,6)Top
5 楼zhaoguoqingluntan(<)回复于 2006-06-02 10:52:00 得分 0
多谢了!Top
6 楼godfather_wang()回复于 2006-06-02 10:54:49 得分 0
select substring(h_add,1,charindex(',',h_add)+1), substring(h_add,charindex(',',h_add)+1,6) from table
Top
7 楼godfather_wang()回复于 2006-06-02 11:03:59 得分 0
select substring(h_add,1,charindex(',',h_add)+1),case when charindex(',',h_add)=0 then '' else right(h_add,len(h_add)-charindex(',',h_add)) end
from table
Top




