Solved

Report Manager- Stored Procedures- Configuring Subscriptions -Max Points

Posted on 2010-11-18
7
319 Views
Last Modified: 2012-05-10

Hello Experts,

My SP is broken

1. Why isnt this SP returning any records?
2. Why aren't the parameters populating?

 
CREATE PROCEDURE EnergyProductLine

	AS

BEGIN

SET NOCOUNT OFF



DECLARE @Start datetime

DECLARE @end datetime

DECLARE @date datetime

DECLARE @energyOrg nvarchar



SET @date = dateadd (mm, -1, getdate()+13)

SET @start= dateadd(m, datediff(m, 0, @date-15), 0)

SET @end = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@date),0))



select distinct vReportdataCurrentPrior.transDate, vReportdataCurrentPrior.extendedstandardCost, vReportdataCurrentPrior.BusinessEntity, 

                      vReportdataCurrentPrior.product, vReportdataCurrentPrior.site, vReportdataCurrentPrior.subproduct, vReportdataCurrentPrior.transYear, 

                      vReportdataCurrentPrior.OrderAmount_LastYear, vReportdataCurrentPrior.InvoiceAmount_LastYear, 

                      vReportdataCurrentPrior.OrderAmount_CurrentYear, vReportdataCurrentPrior.InvoiceAmount_CurrentYear, ExchangeRates.ExchangeRate, 

                      (DATEDIFF(DD, CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, GETDATE()) + 1, GETDATE()) AS DOUBLE PRECISION)) AS DATETIME), 

                      CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, DATEADD(MONTH, 1, GETDATE())), DATEADD(MONTH, 1, GETDATE())) AS DOUBLE PRECISION)) 

                      AS DATETIME)) + 1) - (DATEDIFF(DD, DATEADD(DD, 6 - (DATEPART(DW, CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, GETDATE()) + 1, GETDATE()) 

                      AS DOUBLE PRECISION)) AS DATETIME)) + @@DATEFIRST - 2) % 7, CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, GETDATE()) + 1, GETDATE()) 

                      AS DOUBLE PRECISION)) AS DATETIME)), DATEADD(DD, - ((DATEPART(DW, CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, DATEADD(MONTH, 1, 

                      GETDATE())), DATEADD(MONTH, 1, GETDATE())) AS DOUBLE PRECISION)) AS DATETIME)) + @@DATEFIRST - 2) % 7), CAST(FLOOR(CAST(DATEADD(DD, 

                      - DATEPART(DD, DATEADD(MONTH, 1, GETDATE())), DATEADD(MONTH, 1, GETDATE())) AS DOUBLE PRECISION)) AS DATETIME))) - 1) 

                      / 7 * 2 - CASE (DATEPART(DW, CAST(FLOOR(CAST(DATEADD(DD, - DATEPART(DD, GETDATE()) + 1, GETDATE()) AS DOUBLE PRECISION)) AS DATETIME)) 

                      + @@DATEFIRST - 2) % 7 + 1 WHEN 6 THEN 2 WHEN 7 THEN 1 ELSE 2 END - CASE (DATEPART(DW, CAST(FLOOR(CAST(DATEADD(DD, 

                      - DATEPART(DD, DATEADD(MONTH, 1, GETDATE())), DATEADD(MONTH, 1, GETDATE())) AS DOUBLE PRECISION)) AS DATETIME)) + @@DATEFIRST - 2) 

                      % 7 + 1 WHEN 6 THEN 1 WHEN 7 THEN 2 ELSE 0 END AS MonthWorkingDays, (DATEDIFF(DD, @start, @end) + 1) - (DATEDIFF(DD, DATEADD(DD, 

                      6 - (DATEPART(DW, @start) + @@DATEFIRST - 2) % 7, @start), DATEADD(DD, - ((DATEPART(DW, @end) + @@DATEFIRST - 2) % 7), @end)) - 1) 

                      / 7 * 2 - CASE (DATEPART(DW, @start) + @@DATEFIRST - 2) % 7 + 1 WHEN 6 THEN 2 WHEN 7 THEN 1 ELSE 2 END - CASE (DATEPART(DW, @end) 

                      + @@DATEFIRST - 2) % 7 + 1 WHEN 6 THEN 1 WHEN 7 THEN 2 ELSE 0 END AS WorkingDays, EnergySites.EnergyOrg, 

                      vReportdataCurrentPrior.QTY

FROM         vReportdataCurrentPrior INNER JOIN

                      ExchangeRates ON MONTH(vReportdataCurrentPrior.transDate) = ExchangeRates.XRateMonth AND 

                      vReportdataCurrentPrior.transYear = ExchangeRates.XRateYear AND vReportdataCurrentPrior.currencyCode = ExchangeRates.Currency INNER JOIN

                      EnergySites ON vReportdataCurrentPrior.site = EnergySites.SiteNumber

WHERE     (vReportdataCurrentPrior.transDate BETWEEN @start AND @end OR

                      vReportdataCurrentPrior.transDate BETWEEN DATEADD(yy, - 1, @start) AND DATEADD(yy, - 1, @end)) AND (EnergySites.EnergyOrg = @energyorg) AND

                       (vReportdataCurrentPrior.BusinessEntity = 'energy')





END

Open in new window

0
Comment
Question by:SPLady
  • 4
  • 3
7 Comments
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
If @energyOrg is NULL uou will not get any records.
How do you populate @energyOrg without sending it into the procedure?
0
 
LVL 1

Author Comment

by:SPLady
Comment Utility
Thank you @erick37, I am a newbie of sorts how do I "send it in to the procedure"
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Pass it as a parameter.

EXEC EnergyProductLine @energyOrg = 'foo'
CREATE PROCEDURE EnergyProductLine

    @energyOrg nvarchar(1000)





AS

BEGIN

SET NOCOUNT OFF



DECLARE @Start datetime

DECLARE @end datetime

DECLARE @date datetime

--DECLARE @energyOrg nvarchar

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:SPLady
Comment Utility
Thank you! ok, so If i am calling this procedure from another do I need the date and energy parameters?
ALTER PROCEDURE runEnergyProductLine

    @energyOrg nvarchar(1000)

    

AS

BEGIN

SET NOCOUNT OFF



DECLARE @start datetime

DECLARE @end datetime

DECLARE @date datetime



SET @date = dateadd (mm, -1, getdate()-13)

SET @start = dateadd(m, datediff(m, 0, @date-15), 0)

SET @end = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@date),0))

PRINT @date

PRINT @start

PRINT @end



--then you will use them in a select or even execute the other SP with parameters passing the two dates

select* from energyproductline where transDate between @start and @end

exec EnergyProductLine @start,@end 



END

Open in new window

0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
Comment Utility
Pass in everything you need:

CREATE PROCEDURE EnergyProductLine
    @energyOrg nvarchar(1000)
    ,@start datetime
    ,@end datetime


AS
BEGIN
SET NOCOUNT OFF

--DECLARE @Start datetime
--DECLARE @end datetime
--DECLARE @date datetime
--DECLARE @energyOrg nvarchar
 
0
 
LVL 1

Author Closing Comment

by:SPLady
Comment Utility
Thank you! Erick37 you rock :)
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Glad to help!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now