SQL语句如下:
但此SQL有问题,不能执行
CREATE VIEW v_Report AS 
  select * from (
  sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59'
)sp_Report 是存储过程,返回一个记录集
要求将sp_Report 返回的记录集直接生成视图v_Report ,就是一句SQL实现这个功能
不要告诉这个答案:先把记录集存放入临时表,再从临时表取,现在是需要一句SQL实现这个功能谢谢下面是zjcxc(邹建)的答案CREATE VIEW v_Report AS 
SELECT * FROM openrowset('sqloledb', 'Trusted_Connection=yes','exec sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')可是执行是提示错误:
服务器: 消息 2812,级别 16,状态 62,过程 v_Report,行 2
Could not find stored procedure 'dbo.sp_Report'.而exec sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''
是可以执行的

解决方案 »

  1.   

    sp_Report的所有者是dbo吗?如果不是,将dbo前缀替换为当前所有者。
      

  2.   

    --必须加数据库名.dbo.SELECT * FROM openrowset('sqloledb', 'Trusted_Connection=yes','exec 数据库名.dbo.sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')
      

  3.   

    dbo前面加上了数据库名称还是有错服务器: 消息 7357,级别 16,状态 2,过程 v_Report,行 2
    Could not process object 'exec dbName.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59''. The OLE DB provider 'sqloledb' indicates that the object has no columns.
    OLE DB error trace [Non-interface error:  OLE DB provider unable to process object, since the object has no columnsProviderName='sqloledb', Query=exec dbName.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59',5'].
      

  4.   

    dbName为DBReportServer运行时为
    SELECT * FROM openrowset('sqloledb', 'Trusted_Connection=yes','exec DBReportServer.dbo.sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')
      

  5.   

    指定计算机名试试:
    openrowset('sqloledb', '计算机名;Trusted_Connection=yes','exec 库名.dbo. sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')

    openrowset('sqloledb', '计算机名;用户名;密码','exec 库名.dbo.sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')
      

  6.   

    To:hellowork(一两清风)
    也是报一样的错误服务器: 消息 7357,级别 16,状态 2,过程 v_Report,行 2
    Could not process object 'exec dbName.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59''. The OLE DB provider 'sqloledb' indicates that the object has no columns.
    OLE DB error trace [Non-interface error:  OLE DB provider unable to process object, since the object has no columnsProviderName='sqloledb', Query=exec dbName.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59',5'].
      

  7.   

    你的存储过程没有返回数据吧。在最后用select * from 表名,就可以了。
      

  8.   

    当存储过程不返回记录集时,用openrowset执行就提示上述信息。
      

  9.   

    TO:wangtiecheng
    DBReportServer.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59'在查询分析器里面是返回一个记录集的
      

  10.   

    找一个最简单的存储过程,如下:CREATE PROCEDURE sp_Report
    (
    @P1 datetime,
    @P2  datetime
    )
    ASselect top 10 * from syscolumns
    GO
    试一下。
      

  11.   

    要不然就请楼主把
    'exec DBReportServer.dbo.sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59'''
    换成
    'select * from DBReportServer.dbo.表名'
    试试能否成功,若成功则表示的确是调用存储过程的问题.一点点排除吧.
      

  12.   

    TO:hellowork(一两清风)
    试过,可以的
      

  13.   

    把存储过程内容替换为如下:CREATE PROCEDURE sp_Report
    (
    @P1 datetime,
    @P2  datetime
    )
    ASselect top 10 * from syscolumns
    GO
    试一下。如果没有问题,就检查你的存储过程。
      

  14.   

    wangtiecheng的方法可以,但是我的存储过程一样的返回记录的,为什么不行
      

  15.   

    检查你的存储过程,是否有多个selecct * from 返回记录,或其它的什么原因。
      

  16.   

    存储过程代码如下CREATE ProceDure sp_Report(@BeginDate DateTime,@EndDate DateTime,@IMinute Int)
    AsBegin

        if exists(select 1 from tempdb..sysobjects where xtype='u' and name like '#Temp%') drop table #Temp Select TOP 8000 ID=Identity(Int,0,1) Into #TempIdentity From syscolumns,SysObjects Select DateAdd(mi,@IMinute*ID,@BeginDate) As StartTime,DateAdd(mi,@IMinute*(ID+1),@BeginDate) As EndTime Into #TempMinute From #TempIdentity
    Where DateAdd(mi,@IMinute*(ID+1),@BeginDate)<=@EndDate

    Select  
      Time_Begin= Convert(Varchar(19),A.StartTime,120),
      Time_End  = Convert(Varchar(19),A.EndTime,120),
      Call_Time = convert(datetime,convert(char(10),Time_In,120)),
                    Operator_No,
                    Station_Address,
                    Hour_Name = DATEPART(hh,Time_In) ,
                    Week_Name = DATEPART(wk,Time_In),
                    Month_Name = DATEPART(mm,Time_In) ,  
                   
    From #TempMinute A Left Join User_Calldetail B
    On B.[Time_In] Between A.StartTime And A.EndTime
    Group By 
    Convert(Varchar(19),A.StartTime,120),
    Convert(Varchar(19),A.EndTime,120),
    convert(datetime,convert(char(10),Time_In,120)),Operator_NO,Station_Address,
    DATEPART(hh,Time_In),
    DATEPART(wk,Time_In) ,  DATEPART(mm,Time_In) ,VDN
    End
    GO
      

  17.   

    存储过程是有2个select,但是执行存储过程就只显示了最后一个记录集
      

  18.   

    请楼主把最后一个select去掉测试一下.
      

  19.   

    最后一个、或者是最后二去掉都是提示如下错误服务器: 消息 7357,级别 16,状态 2,过程 v_Report,行 2
    Could not process object 'exec DBReportServer.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59''. The OLE DB provider 'sqloledb' indicates that the object has no columns.
    OLE DB error trace [Non-interface error:  OLE DB provider unable to process object, since the object has no columnsProviderName='sqloledb', Query=exec DBReportServer.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59',5'].
      

  20.   

    问题应该是不能使用临时表,把临时表去掉,直接select数据库中的表应该没有问题。
      

  21.   

    那重新一个简单的存储过程,再试一下看行不行
    create proc lxzm
    as
    select * from orders然后再去试试看
      

  22.   

    CREATE VIEW v_Report AS 
    SELECT * FROM openrowset('sqloledb', 'Trusted_Connection=yes',
    'exec psalary.dbo.sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59''')
      

  23.   

    To lengxiaowei(小伟)
    这句SQL是可以实现 ,问题是这个存储过程里面好像不允许使用临时表,如果使用临时表就会提示如下错误:
    服务器: 消息 7357,级别 16,状态 2,过程 v_Report,行 2
    Could not process object 'exec DBReportServer.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59''. The OLE DB provider 'sqloledb' indicates that the object has no columns.
    OLE DB error trace [Non-interface error:  OLE DB provider unable to process object, since the object has no columnsProviderName='sqloledb', Query=exec DBReportServer.dbo.sp_Report '2006-01-01 00:00:00','2006-01-01 23:59:59',5'].
      

  24.   

    临时表或表变量好像都不能使用。好像insert、delete、update等语句都不可用。
      

  25.   

    TO wangtiecheng你说得没错,好像是这样的不知道有没有什么办法???
      

  26.   

    关注!
    select * from PROCEDURE 
    好像sqlserver的帮助中没有说到可以这么用,一般都是exec PROCEDURE,学习学习select * from FUNCTION 是可以的,楼主不妨麻烦点,把sp_Report改写成一个返回table的函数,问题就解决了。
      

  27.   


    没有什么好办法,除非像你最开始说的,先追加到临时表,再select。SQL Server 2000对于Openrowset中执行存储过程的功能还有待加强。不知道2005是否有所改进。
      

  28.   

    楼主可以在函数中使用带IDENTITY列的表变量来代替临时表.例如:
    将Select TOP 8000 ID=Identity(Int,0,1) Into #TempIdentity From syscolumns,SysObjects
    替换为:
    declare @t table(id int identity,n int)
    insert @t(n) Select TOP 8000 NULL Into #TempIdentity From syscolumns,SysObjects
      

  29.   

    hellowork(一两清风)declare @t table(id int identity,n int)
    insert @t(n) Select TOP 8000 NULL Into #TempIdentity From syscolumns,SysObjects
    执行这句话报错:into附近有语法错误执行这句话
    Select TOP 8000 NULL Into #TempIdentity From syscolumns,SysObjects
    报无法从函数中访问临时表
      

  30.   

    抱歉,复制时未作处理.这样:
    insert @t(n) Select TOP 8000 NULL From syscolumns,SysObjects
    即把Into #TempIdentity 去掉试试.
      

  31.   

    table 变量可用于函数、存储过程和批处理中。尽可能使用表变量而不使用临时表。table 变量有以下优点: (1)table 变量的行为类似于局部变量,有明确定义的作用域。该作用域为声明该变量的函数、存储过程或批处理。 
    在其作用域内,table 变量可像常规表那样使用。该变量可应用于 SELECT、INSERT、UPDATE 和 DELETE 语句中用到表或表的表达式的地方。但是,table 不能用在下列语句中:INSERT INTO table_variable EXEC 存储过程。SELECT select_list INTO table_variable 语句。在定义 table 变量的函数、存储过程或批处理结束时,自动清除 table 变量。(2)在存储过程中使用表变量与使用临时表相比,减少了存储过程的重新编译量。
    (3)涉及表变量的事务只在表变量更新期间存在。这样就减少了表变量对锁定和记录资源的需求。 
    不支持在表变量之间进行赋值操作。另外,由于表变量作用域有限,并且不是持久数据库的一部分,因而不受事务回滚的影响。
      

  32.   

    USE pubs
    GO
    SELECT a.*
    FROM OPENROWSET('SQLOLEDB','seattle1';'sa';'MyPass',
       'SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname') AS a
    GO
    我用我写的存储过程成功了
      

  33.   

    SELECT *
    FROM OPENROWSET('SQLOLEDB','HIS';'HIS';'MANAGER',
       ' exec his.ardata.his.bajk  ''2006-01-01'',''2006-01-01''  ')
      

  34.   

    干嘛要用存储过程??你即然常用这个序数表:
    "Select TOP 8000 ID=Identity(Int,0,1) Into #TempIdentity From syscolumns,SysObjects"
    何不建个固定表在数据库内? 把"#Temp"换成 "NumTable"这样建视图,一句就可以出来了.效率一定要比你的存储过程+视图高得多!方法是死的,人是活的.
      

  35.   

    楼主稍微改下就行了,其实是设置的问题 :)
    SELECT * FROM openrowset('sqloledb', 'Trusted_Connection=yes','set fmtonly off exec sp_Report ''2006-01-01 00:00:00'',''2006-01-01 23:59:59'' set fmtonly on ')
      

  36.   

    zsforever(虎虎
    ===
    按你方法试了 好像不行
      

  37.   

    ==================================
    =  CSDN助手 全面支持CSDN论坛     =
    =  监视、收藏、历史、签名走马灯  =
    ==================================