sp_executesql 使用
这个挺有用可以动态选择表更新
CREATE PROCEDURE UP_HouseTemple_Update
@Cur_Id int,
@House_Id int,
@House_Fw nvarchar(100),
@House_Js int,
@House_Dj nvarchar(100),
@House_Mj float,
@House_Price float,
@Temple_Year int,
@Temple_Type nvarchar(10),
@Temple_Month float
AS
declare @sql nvarchar (1000)
declare @Parm nvarchar(1000)
set @sql='
UPDATE HouseTemple'+cast (@Temple_Year as nvarchar(4)) +' SET
[House_Id] = @House_Id,[House_Fw] = @House_Fw,[House_Js] = @House_Js,[House_Dj] = @House_Dj,[House_Mj] = @House_Mj,[House_Price] = @House_Price,[Temple_Year] = @Temple_Year,
[Temple_Type]=@Temple_Type,Temple_Month=@Temple_Month
WHERE Cur_Id=@Cur_Id'
set @parm=N'@Cur_Id int,
@House_Id int,
@House_Fw nvarchar(100),
@House_Js int,
@House_Dj nvarchar(100),
@House_Mj float,
@House_Price float,
@Temple_Year int,
@Temple_Type nvarchar(10),
@Temple_Month float '
exec sp_executesql @sql,@Parm ,@Cur_Id=@Cur_Id,
@House_Id=@House_Id,
@House_Fw=@House_Fw,@House_Js =@House_Js ,
@House_Dj=@House_Dj ,@House_Mj=@House_Mj,
@House_Price=@House_Price ,@Temple_Year=@Temple_Year,
@Temple_Type=@Temple_Type,@Temple_Month=@Temple_Month
GO
@Cur_Id int,
@House_Id int,
@House_Fw nvarchar(100),
@House_Js int,
@House_Dj nvarchar(100),
@House_Mj float,
@House_Price float,
@Temple_Year int,
@Temple_Type nvarchar(10),
@Temple_Month float
AS
declare @sql nvarchar (1000)
declare @Parm nvarchar(1000)
set @sql='
UPDATE HouseTemple'+cast (@Temple_Year as nvarchar(4)) +' SET
[House_Id] = @House_Id,[House_Fw] = @House_Fw,[House_Js] = @House_Js,[House_Dj] = @House_Dj,[House_Mj] = @House_Mj,[House_Price] = @House_Price,[Temple_Year] = @Temple_Year,
[Temple_Type]=@Temple_Type,Temple_Month=@Temple_Month
WHERE Cur_Id=@Cur_Id'
set @parm=N'@Cur_Id int,
@House_Id int,
@House_Fw nvarchar(100),
@House_Js int,
@House_Dj nvarchar(100),
@House_Mj float,
@House_Price float,
@Temple_Year int,
@Temple_Type nvarchar(10),
@Temple_Month float '
exec sp_executesql @sql,@Parm ,@Cur_Id=@Cur_Id,
@House_Id=@House_Id,
@House_Fw=@House_Fw,@House_Js =@House_Js ,
@House_Dj=@House_Dj ,@House_Mj=@House_Mj,
@House_Price=@House_Price ,@Temple_Year=@Temple_Year,
@Temple_Type=@Temple_Type,@Temple_Month=@Temple_Month
GO