0

我正在使用表变量重写存储过程。基本上我有一个列表,我将其传递给 DataTable,然后将数据表作为表变量传递给存储过程。存储过程可以正确编译,但是当我在 SSMS 或 .Net 中执行它时,我得到了 Invalid object name '@TableVar'。我是新手,所以非常感谢你的帮助。

 Alter PROCEDURE [dbo].[proc]
    (
        @TableVar [dbo].[TableVar] READONLY
    )
    AS
BEGIN
Set nocount on
Declare @MYID INT
Declare @SOMEDate DateTime
Declare @NEWDate Date


select @MYID = some_id,
@SOMEDate = convert(date, db_some_date) from tbl_some
where someval = (select tb.val1 from [@TableVar] as tb);


Merge OneTabl as target
  using (Select x.val1, x.val2, x.val3,x.val4,
                        x.val5,x.val6, x.val7 from [@TableVar] as x)
  as Source

  on val_id = @MYID
  when matched and  @MYID !=NULL then

 update set MDN= Source.[MDN],
                  val1= Source.[val1],
                  val2=Source.[val2],
                  val3=Source.[val3],
                  val4=Source.[val4],
                  val5=Source.[val5],
                  val6=Source.[val6]

  when not matched and @MYID !=NULL then  
   insert  
   values (Source.[val1],
           Source.[val2],
           Source.[val3],
               Source.[val4],
               Source.[val5],
               Source.[val6],
               Source.[val7],
               [@MYID]
      )      ;
end 
4

1 回答 1

1

我按照建议从 tablevar ref 中删除了 [] 括号,谢谢。谢谢@Habo

于 2012-09-10T17:31:28.143 回答