当前位置: 代码迷 >> Sql Server >> 多列数据操作有关问题
  详细解决方案

多列数据操作有关问题

热度:51   发布时间:2016-04-24 10:09:07.0
多列数据操作问题
select t1.ID ,t1.Number ,t1.Name ,t1.Item  ,t1.WorkTime ,t2.Department  from Table_Information as t1,Table_Name  as t2 where t1.Number='S1100'and t1.Name='甲一'and t1.Item ='item1'and t1.Name =t2.Name 
单一的 选中 结果 是 ok的 

如果 想要满足t1.Name和t1.Item的 所有  t1.Number列的数据 ,则 select....where的时候 不加t1.Number
同理t1.Name,t1.Item也这样做 
有时需要 满足某两列的 或者 三列的数据 (t1表有很多列)

有没有其他方法 ,可以 实现的( 除了 每一种情况都 select...where)

不知我是否描述清楚
------解决方案--------------------
可以加个变量开关,开启条件。
比如
declare @i int =0
select * from tb
where ((@i = 0) or 条件)

这个时候,当@i = 0的时候,条件无效,不然必须满足条件,@i的类型,值根据需要可以任意锁定。
  相关解决方案