简单的SQL表引用

时间:2014-10-14 13:52:08

标签: sql sql-server tsql temp

我正在尝试使用变量表来引导镜像报告sproc,以便我可以推出与此IS号相关的单一报告:

CREATE PROCEDURE [dbo].[report
(@Date DATETIME='11/11/2011')
AS
BEGIN
   SELECT *
   INTO #Temp
   FROM dbo.vwview
   WHERE
        Date = @Date

   DECLARE @tblnewReport TABLE(IS varchar(8))

   SELECT subreportIS
   INTO @tblnewReport
   FROM #Temp

基本上,我的@tblnewReport就是问题所在。任何想法将不胜感激!

1 个答案:

答案 0 :(得分:3)

试试这个:

 CREATE PROCEDURE [dbo].[report
(
 @Date DATETIME='11/11/2011'
)
AS
BEGIN

SELECT *
INTO #Temp
FROM  dbo.vwview
WHERE
        Date = @Date
DECLARE @tblnewReport TABLE
(IS varchar(8))

INSERT
INTO @tblnewReport
SELECT SubreportIS FROM #Temp