use dbname
gosp_.....
sqlserver里是这样的

解决方案 »

  1.   

    忘了说了,现在要求把我的这些代码也做成一个存储结构
    sp_getResultsByKey(keyword)
    就是输入一个关键字,然后返回一个ID,detail的记录集
      

  2.   

    borgvardt(maximius):
    谢谢你的回复,我是菜鸟,还有些细节搞不懂
    就像刚才所说,查询ID比较容易,比如select ID from productList where productname like '%keyword%'但是那个getDetailByID每次只能根据一个id返回一个detail
    怎么把所有的结果都取出detail,然后返回一个记录集呢谢谢指教!
      

  3.   

    按照你情况sp_getDetailByID(ID)改用函数比较好
      

  4.   

    看lz的getDetailByID怎么写了.存储过程是能返回记录集的
      

  5.   

    create procedure sp_getResultsByKey
    @keyword varchar(20)
    as
    select identity(int,1,1) 'num',ID,null 'detail' 
    into #
    from productList 
    where productname like '%'+@keyword+'%'declare @i int
    select @i=1create table #tmp(detail varchar(1000))
    while @i<=(select max(num) from #)
    begin
          insert #tmp exec sp_getDetailByID(@i)
          update # 
          set detail=(select detail from #tmp)
          where num=@i
          truncate table #tmp      set @i=@i+1
    endselect ID,detail from #drop table #
      

  6.   

    如果可以不用存储过程的话,并且两个数据库在同一个sql实例下。在db1中执行
    select a.id,b.detail
    from productList a,db2.dbo.id介绍表 b
    where a.id=b.id and .....
      

  7.   

    to: vivianfdlpw() 
    两个红星果然厉害,不过我还看不太懂
    先学习学习给分啦,不懂再问 ^_^