在表内行复制
ID 事件ID 地点 时间 人数
1 3 fake street 3:00pm 30
2 4 null 5:00pm null
现在想把@FromID = 1的信息复制到@ToID = 2上,只有当字段为null时才复制,事件ID不变 输出结果为 ID 事件ID 地点 时间 人数
1 3 fake street 3:00pm 30
2 4 fake street 5:00pm 30 请问是否为null怎么判断,这个存储过程怎么写?
谢谢!
ID 事件ID 地点 时间 人数
1 3 fake street 3:00pm 30
2 4 null 5:00pm null
现在想把@FromID = 1的信息复制到@ToID = 2上,只有当字段为null时才复制,事件ID不变 输出结果为 ID 事件ID 地点 时间 人数
1 3 fake street 3:00pm 30
2 4 fake street 5:00pm 30 请问是否为null怎么判断,这个存储过程怎么写?
谢谢!
解决方案 »
- 求一条调用函数的sql
- 求一个SQL语句,谢谢!
- SQL查询Excel表出现问题,以及两个SQL表如何连接Excel表查询
- sql语句如何实现同一张表里交叉相等的记录并排显示出来?
- 成员 AutoSync 失败。对于要在插入后自动同步的成员,类型必须具有自动生成的标识或在插入后未被数据库修改的键。
- 創建一個触发器
- 查询表结构,在线等待高手。
- 如何在虚拟机中安装SQL2000SP$“复制”组件?
- Haiwer 好人呀 !!! up 者有分 !!!!
- 求一存储过程替换数据库中某一字段一部分值!!!!
- sql条件语句?
- 水晶报表里面当数据库专家中有两个表时候,老是会弹出数据库登陆 对话框。如果一个表的话就很正常。这是什么原因啊。。
我有很多列,每个都要进行上述三个操作?
declare @FromID int,@ToID int
SET @FromID= 1
SET @ToID = 2
INSERT INTO table1(ID ,事件ID,地点,时间,人数 )
select ID,事件ID,地点,时间,人数
from table
where (ID is null
or 事件ID is null
or 地点 is null
or 时间 is null
or 人数 isnull) and ID=@FromID AND ID =@ToID
update table1
set 事件ID=isnull(a.事件ID,b.事件ID)
,地点=isnull(a.地点,b.地点)
,时间=isnull(a.时间,b.时间)
,人数=isnull(a.人数,b.人数)
from table1 a,(select * from table1) b
where a.事件ID=1
and b.事件ID=2
oh,my God, 我查了一下数据库,不仅仅是null,还有一些empty string,怎么判断呀?
多谢,多谢!
update table1
set 事件ID=isnull((case when a.事件ID ='' then null else a.事件ID end),b.事件ID)
,地点=isnull((case when a.地点 ='' then null else a.地点 end),b.地点)
,时间=isnull((case when a.时间 ='' then null else a.时间 end),b.时间)
,人数=isnull((case when a.人数 ='' then null else a.人数 end),b.人数)
from table1 a,(select * from table1) b
where a.事件ID=1
and b.事件ID=2自己再看一下吧!!
而且直接连接自己不需要(select * from table1) b吧?update table1
set 地点=isnull((case when a.地点 ='' then null else a.地点 end),b.地点)
,时间=isnull((case when a.时间 ='' then null else a.时间 end),b.时间)
,人数=isnull((case when a.人数 ='' then null else a.人数 end),b.人数)
from table1 a,table1 b
where a.事件ID=1
and b.事件ID=2