SELECT FROM stored procedure?

后端 未结 4 1756
我寻月下人不归
我寻月下人不归 2020-12-22 12:22

If I have a stored proc in SQL Server 2008, I know I can run it from management studio like so:

exec rpt_myproc @include_all = 1, @start_date = \'1/1/2010\'
         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 13:00

    What tool are you using? You should be able to specify the query type (i.e. SQL, or stored proc, etc)

    Haven't used that tool before but a quick google came up with this example (not sure if it will help you)

    Using a stored procedure in 5.x
    
    This example uses a stored procedure to populate a table before report design or execution. As shown in the comments, the table StoredProcResults must already exist. Every time a report is created or viewed this stored procedure will update the results of the StoredProcResults table. For 6.x follow these instructions but treat the SP as a regular datasource.
    // Customize a report on the fly prior to execution on a per user basis
    
    public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet){    
        /*this sample uses the adventure works database    Here is the definition of the table and     stored procedure created for this report.     
            CREATE TABLE [dbo].[StoredProcResults](    
                [ProductID] [int] NOT NULL,    
                [OrderQuantity] [int] NOT NULL,    
                [Total] [int] NOT NULL,    
                [DueDate] [smalldatetime] NOT NULL    
            ) ON [PRIMARY]    
    
            CREATE PROCEDURE DoCustomAction (
                @date1 as smalldatetime,
                @date2 as smalldatetime    
            )   AS    
            BEGIN    
                insert into StoredProcResults    
                select ProductID,OrderQty,LineTotal,ModifiedDate    
                from Sales.SalesOrderDetail    
                where ModifiedDate >= @date1 and ModifiedDate <= @date2    
            END    
        */    
    
        string currentReportName =    HttpContext.Current.Request.QueryString["rn"];    
        if (currentReportName == "StoredProcExample")    {
            SqlConnection myConnection = new SqlConnection(Izenda.AdHoc.AdHocSettings.SqlServerConnectionString);        
            SqlCommand myCommand = new SqlCommand("DoCustomAction", myConnection);        
            // Mark the Command as a SPROC        
            myCommand.CommandType = System.Data.CommandType.StoredProcedure;        
            // Add Parameters to SPROC        
            SqlParameter parameterdate1 = new SqlParameter("@date1", System.Data.SqlDbType.SmallDateTime);        
            parameterdate1.Value = "1/1/2003";        
            myCommand.Parameters.Add(parameterdate1);        
            SqlParameter parameterdate2 = new SqlParameter("@date2", System.Data.SqlDbType.SmallDateTime);        
            parameterdate2.Value = "12/31/2003";        
            myCommand.Parameters.Add(parameterdate2);        
    
            try{            
                myConnection.Open();            
                myCommand.ExecuteNonQuery();        
            }
            finally{            
                myConnection.Close();        
            }    
        }
    }
    

提交回复
热议问题