简单问题(连接查询),将第一个表的第一个字段与第二个表的第一个字段做为连接条件,此SQL语句怎么写,注意字段名称是不定的。

解决方案 »

  1.   

    declare @col1 varchar(20)
    declare @col2 varchar(20)
    select top 1 @col1=[name] from syscolumns where id=object_id('a') order by colid
    select top 1 @col2=[name] from syscolumns where id=object_id('b') order by colid
    exec('select * from a,b where a.'+@col1+'=b.'+@col2)
      

  2.   

    declare @str varchar(5000)set @str= ('select * from [表1] a join [表2] b
    on a.'+(select name from syscolumns where id=object_id ('[表1]') and colid =1) +'=b.'+
    (select name from syscolumns where id=object_id ('[表2]') and colid =1))exec(@str)
      

  3.   

    我有两个表 A、B ,一般来说SQL语句是这样。
    select * from a left join b on a.AID = b.BID但如果我不知道表A和B下有字段名称AID、BID,只知道它们分别都处于表中的第一个字段,这时应该如何来写这条SQL语句呢?
      

  4.   

    我要求要用一第SQL语句来完成。
      

  5.   

    我要求要用一条SQL语句来完成只用一条SQL语句怎么来完成
      

  6.   

    exec('select * from a,b where a.列名=b.列名')