declare @temp table(client_id int,prod_id int,how int,now datetime)
insert into @temp select  client_id,prod_class_id,how,now from clientoutput where now>='2009-11-26' and head_code is null 
select * from @temp where @temp.client_id!=5
报错:
消息 137,级别 15,状态 2,第 4 行
必须声明标量变量 "@temp"。主要是这一句:where @temp.client_id!=5但是这样就可以:select * from @temp as t where t.client_id!=5为什么不能直接@temp.client_id!=5?

解决方案 »

  1.   

    @temp是一个变量,不是一个对象名
      

  2.   

    这个是SQL语法 或者说是一种规定 
      

  3.   

    表变量不能直接限定列。可以使用别名。select * from @temp t where t.client_id!=5 
      

  4.   

    select * from @temp t where t.client_id!=5 
      

  5.   

    表变量具有以下限制:
    不能直接在表变量上创建索引,但是可以在表变量声明时创建 PRIMARY KEY 或 UNIQUE 约束,并由此创建唯一聚集索引。并且表变量一旦被声明,表变量的架构就不允许被更改。
    在 SQL SERVER 2000 中,不能对表变量使用 SELECT INTO 和 INSERT INTO EXEC 语句;而 SQL SERVER 2005 支持对表变量使用 INSERT INTO EXEC 语句。
    在引用表变量的列名时,不能使用表变量名限制列名,但可以用表变量的别名限制。对于涉及修改表变量的查询,查询优化器将不能生成并行执行计划。
      

  6.   

    但是这样就可以:select * from @temp as t where t.client_id!=5 只能这样.