Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Trying to pass dates as parameters to dynamic SQL string then execute

$
0
0

I've been working on some TSQL where I have a stored procedure that accepts two date parameters for a report that will be built in Reporting Services. Here's the created stored procedure:

SQL
CREATEPROCEDURE[dbo].[spReportDom2](@FromDateDateTime,@ToDateDateTime)ASBEGINDECLARE@ToplineTABLE(TopLinenumeric(9,2),OfficeNamevarchar(100))DECLARE@CostOfGoodsTABLE(CostOfGoodsnumeric(9,2),OfficeNamevarchar(100))DECLARE@Querynvarchar(1000)DECLARE@Query2nvarchar(1000)-------ARIZONASELECT@Query=' SELECT SUM(Amount) AS TopLine, (SELECT Office.Name  FROM Arizona.dbo.Office  WHERE  Office.ID=VW.OfficeID) as OfficeName FROM Arizona.dbo.ViewIncomeStatement VW (NOLOCK) WHERE SectionName=''Revenues'' AND VW.EffectiveDate BETWEEN ''04/11/2015'' AND ''04/18/2015'' GROUP BY OfficeID'SELECT@Query2=' SELECT SUM(Amount)as CostOfGoods,...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>