select username from (select name from [table] where id=1) new 
where uid=2 
这句语法是对得。

解决方案 »

  1.   

    select a.[name] from (select [name],uid from 表名 where [id]=1)  as a 
    where a.uid=2
      

  2.   

    declare @表明 varchar(100)
    set @表明='xxxxxx'
    exec('select * from '+@表明)
      

  3.   

    select name from (select * from table where id=1) new 
    where id=2                                               
    ---
    ??????
      

  4.   

    要用别名,而且用的字段扼也要加。
    select 和where后的字段一定要在结果集中
      

  5.   

    select username from (select name ,uid  from [table] where id=1) new 
    where uid=2 
      

  6.   

    username 当然不行了,要用name ,你要选择的列username在子查询吗???select name from (select * from table where id=1) as new 
    where id=2
      

  7.   

    我曾看到过一篇把oracle和mssql比较的文章,那里边提到可以用子查询的结果来作表名或者列名,但是写的很笼统,没看懂   :(
      

  8.   

    select username from (select name as username,id as uid from table where id=1)  as new 
    where uid=2    你在外面用到的字段名一定要在括号中的SELECT中有这个列名.
      

  9.   

    declare @表明 varchar(100)
    set @表明='xxxxxx'
    exec('select * from '+@表名)
    这个是可以的,
    @表名这个变量可以用游标,循环赋值的
    但是
    如果你想做
    exec('select count(*) from '+@表名)
    中取得 count(*) ,这样是无能为力的!
    我今天下午也正在想这个问题
      

  10.   

    declare @strSQL  varchar(500)   select @strSQL =name from table where id=1
       SET @strSQL ='select username from '+@strSQL+' where uid=2 '
       EXEC(@strSQL)
      

  11.   

    我曾看到过一篇把oracle和mssql比较的文章,那里边提到可以用子查询的结果来作表名或者列名,但是写的很笼统,没看懂 re:你说的是子查询:select * from (select * from 表1) 别名