比如
   SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
   SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC
   SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
   SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
   SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC
   SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC如何在存储过程中获取这个数据?@name1=SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC??

解决方案 »

  1.   

      SELECT name1,name2,name3,name4,name5,name6 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
      

  2.   

    SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC 
    union all
    SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC 
    union all
    SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
    union all 
    SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
    union all 
    SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC 
    union all
    SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC 
      

  3.   

    我的意思是,我现在要做一个统计表,而统计中每个单元的数据涉及一套sql,现在我想把全部sql都通过一个存储过程来实现,但是不知道如何在存储过程中接受sql查询到的数据!
      

  4.   

    create proc P_test
    as 
    SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC 
    union all 
    SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC 
    union all 
    SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC 
    union all 
    SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC 
    union all 
    SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC 
    union all 
    SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC 
    还是没听明白~~
      

  5.   


    @name1=SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC 
    修改为
    SELECT @name1 = name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC 
      

  6.   

    楼主是想表达,怎么把查出来的一个字段赋值个一个变量吧,如果是,就是我说的方法
    但要注意,你必须保证返回的记录只有1行,不然,要抱错,所以为了解决这个问题,加上TOP1,就不管它返回多少行了SELECT TOP 1 @name1 = name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC