日期:2014-05-17 浏览次数:20679 次
ALTER PROCEDURE [dbo].[cs]
@id int,@xm varchar(50),@bday DateTime,@tel varchar(50),@qq varchar(50)
AS
BEGIN
SET NOCOUNT ON;
update table1 set xm=@xm where id=@id and xm is null
update table1 set bday=@bday where id=@id and bday is null
update table1 set tel=@tel where id=@id and tel is null
update table1 set qq=@qq where id=@id and qq is null
END
update table1 set
xm=isnull(xm,@xm),
bday=isnull(bday,@bday),
tel=isnull(tel,@tel),
qq=isnull(qq,@qq),
where id=@id
------解决方案--------------------
多次更新也可以的。
------解决方案--------------------
UPDATE table1 SET xm = ISNULL(xm, @xm), bday = ISNULL(bday, @bday), tel = ISNULL(tel, @tel), qq = ISNULL(qq, @qq) WHERE id = @id
------解决方案--------------------
ALTER PROCEDURE [dbo].[cs]
(@id int, @xm varchar(50), @bday DateTime, @tel varchar(50), @qq varchar(50))
AS
BEGIN
SET NOCOUNT ON;
declare @sql varchar(6000)
select @sql='update table1 set '
select @sql=@sql+case when xm is null then ' xm='''+@xm+''',' end
+case when bday is null then ' bday='''+convert(varchar(30),@bday,120)+''',' end
+case when tel is null then ' tel='''+@tel+''',' end
+case when qq is null then ' xm='''+@qq+''',' end
from table1 where id=@id
select @sql=left(@sql,len(@sql)-1)+' where id='+rtrim(@id)
exec(@sql)
END
------解决方案--------------------