Quantcast
Channel: SQLServerCentral » Reporting Services » Reporting Services » Latest topics
Viewing all articles
Browse latest Browse all 2791

what' wrong with my script

$
0
0
I created a procedure to filter data somehow the if....else condition didn't bind the queryuse AdventureWorks2008R2GOalter PROCEDURE dbo.filterbydate(@startdate datetime,@endDate datetime)asBeginDeclare@start datetime,@end datetimeset @start = @startdateset @end = @endDate IF datediff(yy, @startdate, @endDate) >1 Begin RAISERROR ('Date range can not exceed one year',10,1) End Else if @startdate is null and @endDate is not null Begin set @startdate=dateadd(yy, -1, @endDate) End Else if @endDate is null and @startdate is not null Begin set @enddate = dateadd(yy, 1, @startdate) end Else if @startdate is null and @endDate is null Begin set @endDate = getdate() set @startdate = dateadd(yy, -1, getdate()) end SELECT SH.OrderDate ,SH.SalesOrderNumber ,SD.OrderQty ,SD.LineTotal ,P.Name AS [Product] ,PS.Name AS [Subcategory] FROM Sales.SalesOrderHeader AS SH INNER JOIN Sales.SalesOrderDetail AS SD ON SH.SalesOrderID = SD.SalesOrderID INNER JOIN Production.Product AS P ON SD.ProductID = P.ProductID INNER JOIN Production.ProductSubcategory AS PS ON PS.ProductSubcategoryID = P.ProductSubcategoryID INNER JOIN Production.ProductCategory AS PC ON PC.ProductCategoryID = PS.ProductCategoryIDWHERE PC.Name = 'Clothing' AND SH.OnlineOrderFlag = 0 AND (SH.OrderDate BETWEEN (@start) AND (@end))End

Viewing all articles
Browse latest Browse all 2791

Trending Articles