现有一张表A
有字段 itemCode 和groupNo
itemCode表中数据唯一,
Groupno表中数据不唯一,而且有可能是0或者NULL
如何根据itemCode和groupNo查出满足条件的数据
当GroupNo为0或者为NULL只会查出itmeCode所对应的一条记录,
否则查出groupNo,ItemCode所对应的所有记录
请问此sql语句怎么写?
解决方案 »
- 请教前台AccessDataSource中使用后台变量的问题,谢谢
- MenuItemClick事件没能激发
- System.InvalidOperationException: ConnectionString 属性尚未初始化。
- Asp.Net怎么面向对象设计?
- 紧急求助:如何判断dataset里是否有值
- 调用oracle存储过程,出现PLS-00201: 必须说明标识符 'GUEST_GETPAGE_ONE.SP_PAGE',怎么处理?
- 谁能给个asp2.0中callback机制中 有个客户端函数,包含context参数的那个context的用法?
- 请问,我要得到 DATAGRID中 CHECKBOX控件的值,怎么写代码,我已经写了个代码,但是无法实现,您来帮我看看
- 请大家来看一下!我的msdn98装上去后总是说有个文件打不开!
- 上传文件类型控制?
- IIS发布网站后服务器端控件无法显示
- 将存储过程exec方式改为exec sp_executesql
where (groupNo = 值 or isnull(groupNo,0)=0)
是不是这个意思?
select * from tb where groupno <>0 and groupno is not null
where groupNo=
(case when isnull(groupNo,0)=0 then '值' else groupNo end)
where
ItemCode=@ItemCode
and (isnull(groupNo,0)=0 or groupNo=@groupNo)
where
ItemCode=@ItemCode and (isnull(groupNo,0)=0 or groupNo=@groupNo)
ItemCode数据;同时也需要groupno不为0和不为NULL时候的 所有数据。select groupNo,ItemCode from table where groupno <>0 and groupno is not null
--查询出 groupno 不为 0 和 null时候的数据select ItemCode form table
--不考虑 groupNo 单独查询出ItemCode 那么完整的语句就是:
select groupNo,ItemCode from table where groupno <>0 and groupno is not null
union
select ItemCode form table
--将两条记录合并,采用字段同值合并,防止ItemCode重复。
itemCode表中数据唯一,
Groupno表中数据不唯一,而且有可能是0或者NULL
++itemCode 表中数据唯一,
Groupno 表中数据不唯一,而且有可能是0或者NULL
想表达
groupno不为0或者null的时候
select * from tb where itemCode='值' and groupno='值'
groupno为0或者null的时候
select * from tb where itemCode='值
where 主键 in
(
select 主键 from tb where groupno is null or groupno !=0
) and itemCode='值' and groupno='值'union select * from tb
where 主键 in
(
select 主键 from tb where groupno is null or groupno =0
) and itemCode='值'
按照楼主的意思
select itemCode,GroupNo from A where GroupNo =0 or GroupNo is null
--不过这样取出来的itemCode 肯定不会是一条,除非你表里就只有一条。
--是不是还有别的唯一字段???
当GroupNo不为0或null的时候
select itemCode,groupNo from A where GroupNo <> 0 and
GroupNo is not null
--如果按照楼主这个需求那么这两个条件的话
也就是
select itemCode,GroupNo from A