I have a parameter called Reporting Level in my Report where you can choose from 4 options:
Company
BDM
Region
Site
What I want to be able to do is this:
Select BDM and this opens another Parameter call BDM List (This is based on Get Values from a query), but I want the other Parameters to stay greyed out. Once a selection is made from the BDM List then the Time and Date Parameter becomes available.
Is this possible?
These are my Datasets for the BDM List and Region List:
SELECT SiteInfo FROM
((SELECT DISTINCT BDM, Region, SiteName As SiteInfo
FROM Site
WHERE #ReportingLevel = 'BDM'
union all
SELECT DISTINCT BDM, Region, SiteName As SiteInfo
FROM Site
WHERE #ReportingLevel = 'Region' )
union all
SELECT DISTINCT BDM, Region, SiteName As SiteInfo
FROM Site
WHERE #ReportingLevel = 'SiteName') AS QRY2
This is my main Dataset:
SELECT OccupancyDetail.CalendarYear, OccupancyDetail.CalendarMonth, SUM(OccupancyDetail.No_of_Nights) AS No_of_Nights,
SUM(OccupancyDetail.Capacity) AS Capacity
FROM OccupancyDetail INNER JOIN
Site ON OccupancyDetail.Site_Skey = Site.Site_Skey
WHERE (OccupancyDetail.ReferenceDate = convert(Date,getdate()))
AND CASE WHEN #Time = 'YEAR' THEN CAST(CalendarYear as varchar(4)) else CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) end in (#Dates)
AND Site.BDM IN (#BDM)
AND Site.Region IN (#Region)
AND Site.SiteName IN (#SiteName)
GROUP BY OccupancyDetail.ReferenceDate, OccupancyDetail.CalendarYear, OccupancyDetail.CalendarMonth
Time Dataset
select DateChoice FROM
(select distinct CalendarYear, 1 as MonthNumber,CAST(CalendarYear as varchar(4)) as DateChoice from Time
where #Time = 'YEAR'
union all
select Distinct CalendarYear, MonthNumber,CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) as DateChoice from Time where #Time = 'MONTH') as QRYDATA
ORDER BY CalendarYear,MonthNumber
I hope you can help this is my 3rd day working on this.
Thanks
Wayne
I believe you are looking to use cascading parameters, here are a few links that should help you.
http://technet.microsoft.com/en-us/library/dd255197.aspx
http://thevirtualzoneblog.wordpress.com/2011/03/30/creating-cascading-parameter-reports-using-sql-server-reporting-services-v2008/
With the first link, go to the section marked 'To create a dataset to provide values for a dependent parameter'. This next one shows the parameters as greyed out before the parent has an option selected:
http://www.resultdata.com/adding-cascading-parameters-to-a-ssrs-report/
Update
I have found a video tutorial for you:
http://www.youtube.com/watch?v=VAYGupJcHkU
Related
I am using the below below code, however I am running into an issue where I have been trying to rename the the column named "(No Problem Name"). I haven't figured out a solution to rename the colume "Effective Data". Currently all I can get the column to read it "No Problem Here".
SELECT DISTINCT ded.PlanYear ,ded.BenefitType ,ded.ProductID
,convert(datetime, ded.CoverageEffDate, 101) ,megp.GroupID
FROM DET_ENROLLMENT_DETAILS ded
INNER JOIN MST_EMPLOYER_GROUP_PLAN megp ON ded.ProductID = megp.ProductID
WHERE
--ded.CoverageEffDate LIKE '%2019%' ded.CoverageEffDate >= '2019-09-30' AND
ded.BenefitType = 'MEDICAL'
Change the 4th column to start with [] =
[columnname] = convert(datetime, ded.CoverageEffDate, 101)
Inside the [] you can provide the name of the colum.
Alternatively you can use AS:
convert(datetime, ded.CoverageEffDate, 101) AS ColumnName
Use 'AS name'
SELECT DISTINCT ded.PlanYear ,ded.BenefitType ,ded.ProductID
,convert(datetime, ded.CoverageEffDate, 101) AS 'convert', megp.GroupID
FROM DET_ENROLLMENT_DETAILS ded
INNER JOIN MST_EMPLOYER_GROUP_PLAN megp ON ded.ProductID = megp.ProductID
WHERE
--ded.CoverageEffDate LIKE '%2019%' ded.CoverageEffDate >= '2019-09-30' AND
ded.BenefitType = 'MEDICAL'
I am trying to grab the last (latest) blog article's link for each month using a stored procedure but I cannot seem to find a way past my problem.
Currently, my code below repeats the (the latest blog article's) 'LINK' column like so:
SELECT AVG(DATEPART(mm, b.blog_date)) AS MonthNum --CANNOT USE MONTHNUM IN ORDER BY UNLESS WRAPPED WITH AVG() [average], weird but works
, CAST(DateName(month, DateAdd(month, Datepart(MONTH, b.blog_date), -1)) AS varchar(24)) AS MONTH
, CAST(DATEPART(YEAR, b.blog_date) AS varchar(4)) AS YEAR
, CAST(count(b.blog_content) AS varchar(24)) as ARTICLES
, (SELECT TOP (1) b.blog_url
FROM Management.Blog
WHERE (website_owner_id = 2)
GROUP BY blog_date
, blog_url
ORDER BY blog_date DESC
) AS LINK
, CAST(DateName(month, DateAdd(month, Datepart(MONTH, b.blog_date), -1)) AS varchar(24)) + CAST(DATEPART(YEAR, b.blog_date) AS varchar(4)) AS ID
, blog_date as DATE
FROM Management.Blog b
WHERE b.website_owner_id = 2
GROUP BY CAST(DateName(month, DateAdd(month, Datepart(MONTH, b.blog_date), -1)) AS varchar(24))
, CAST(DATEPART(YEAR, b.blog_date) AS varchar(4))
, b.blog_url
, blog_date
, CAST(DateName(month, DateAdd(month, Datepart(MONTH, b.blog_date), -1)) AS varchar(24)) + CAST(DATEPART(YEAR, b.blog_date) AS varchar(4))
ORDER BY DATE DESC
I understand the code is horrible to read (& probably to execute on the SQL server too) but I'm in a position where I am only new to SQL server (coming from MySQL where I've only really had to use a basic select query) and I am open to any suggestions to changing the query and/or table design.
Essentially there should be no duplicates of the ID column (which is only really added in to assist in removing the duplicates and can be omitted if need be).
Without sample data I'm unable to test whether this would work
After FROM Management.Blog b
Add this
INNER JOIN(
SELECT MonthNum = DATEPART(MONTH, BL.blog_date))
,blog_date
,RN = ROW_NUMBER()OVER(ORDER BY BL.blog_date DESC)
,BL.blog_url
FROM Management.Blog BL
) X ON B.blog_date = X.blog_date
AND X.RN = 1
Replace
(SELECT TOP (1) b.blog_url
FROM Management.Blog
WHERE (website_owner_id = 2)
GROUP BY blog_date
, blog_url
ORDER BY blog_date DESC
) AS LINK
with
X.blog_url AS [LINK]
change this in GROUP BY
, b.blog_url
with
, x.blog_url
I non-functioning query usually does not do a very good job of conveying what someone wants. Based on your explanation:
I am trying to grab the last (latest) blog article's link for each month
I would expect something like this:
SELECT b.*
FROM (SELECT b.*,
ROW_NUMBER() OVER (PARTITION BY YEAR(b.blog_date), MONTH(b.blog_date), b.blog_url, b.website_owner_id
ORDER BY blog_date DESC
) as seqnum
FROM Management.Blog b
) b
WHERE b.website_owner_id = 2 AND
seqnum = 1;
We get a new batch of widgets each month. We know the product codes of these widgets which will be is stock, waiting to be used. Each also has an availability date, after which it can be used.
Table WidgetStock
Columns: WidgetID, AvailabilityDate,
Another table has the uses of the widget, ie when it was first used.
Table WidgetsUsed
Columns: datetime, Operator
I'd like to see by day and hour the amount of fresh widgets that I have used for the first time, since the start of the month. The widgets will be used multiple times, so a simple distinct count by hour is not really enough, as widgets would be double counted.
In my mind this would require looking at a list of available numbers, which is updated for each line of a group by query.
The below query will not work, but hopefully it shows what I am trying to achieve:
declare #StartofMonth datetime
set #StartofMonth = '20160901'
select CONVERT(varchar, wu.datetime, 103)'Date'
, convert(char(2), wu.datetime, 108)'Hour'
--Problem Line below
, SUM(case when wu.StockNo in (select ba.NUMBER
from widgetStock ba
where availability_date between CONVERT(varchar, wu.datetime, 103) and #StartofMonth) then 1 else 0 end) 'Number Used'
from widgetsUsed wu
left join widgetStock ws on wu.StockNo = ws.NUMBER
where wu.OPERATOR = 'WidgetWorld'
and DATETIME between '20160914' and '20160916'
group by CONVERT(varchar,wu.datetime,103), convert(char(2), wu.datetime, 108)
Any help with this is appreciated. Thanks in advance.
If understood your requirement then below script may solve your problem
declare #StartofMonth datetime
set #StartofMonth = '20160901'
select CONVERT(varchar, wu.datetime, 103)'Date'
, convert(char(2), wu.datetime, 108)'Hour'
, SUM(ISNULL(ba.NUMBER,0)) 'Number Used'
from widgetsUsed wu
left join widgetStock ws on wu.StockNo = ws.NUMBER
LEFT JOIN widgetStock ba ON wu.StockNo = ba.NUMBER AND availability_date between CONVERT(varchar, wu.datetime, 103) and #StartofMonth
where wu.OPERATOR = 'WidgetWorld'
and DATETIME between '20160914' and '20160916'
group by CONVERT(varchar,wu.datetime,103), convert(char(2), wu.datetime, 108)
I'm creating a report in a SQL Server database. I will show it's code first and then describe what it does and where is problem.
SELECT
COUNT(e.flowid) AS [count],
t.name AS [process],
CAST(DATEPART(YEAR, e.dtcr) AS VARCHAR) + '-' + CAST(RIGHT('0' + RTRIM(DATEPART(MONTH, e.dtcr)), 2) AS VARCHAR) + '-' + CAST(RIGHT('0' + RTRIM(DATEPART(DAY, e.dtcr)), 2) AS VARCHAR) AS [day]
FROM
dbo.[Event] e
JOIN
dbo.Flow f ON e.flowid = f.id
JOIN
dbo.WorkOrder o ON f.workorderno = o.number
AND o.treenodeid IN (26067, 26152, 2469, 1815, 1913) -- only from requested processes
JOIN
dbo.TreeNode t ON o.treenodeid = t.id -- for process name in select statement
JOIN
dbo.Product p ON f.productid = p.id
AND p.materialid NOT IN (26094, 27262, 27515, 27264, 28192, 28195, 26090, 26092, 26093, 27065, 26969, 27471, 28351, 28353, 28356, 28976, 27486, 29345, 29346, 27069, 28653, 28654, 26735, 26745, 28686) -- exclude unwanted family codes
WHERE
e.pass = 1 -- only passed units
AND e.treenodeid IN (9036, 9037, 9038, 9039, 12594, 26330) -- only from requested events
AND e.dtcr BETWEEN '2015-12-01 00:00:00.000' AND '2016-05-31 23:59:59.999' -- only from requested time interval
GROUP BY
DATEPART(YEAR, e.dtcr), DATEPART(MONTH, e.dtcr), DATEPART(DAY, e.dtcr), t.name
ORDER BY
[day]
What query does is count units that passed specific events in a time periods (with some filters).
Important tables are:
Event - basically log for units passing specific events.
Product - list of units.
Output is something like this:
COUNT PROCESS DAY
71 Process-1 2015-12-01
1067 Process-2 2015-12-01
8 Process-3 2015-12-01
3 Process-4 2015-12-01
15 Process-1 2015-12-02
276 Process-2 2015-12-02
47 Process-3 2015-12-02
54 Process-4 2015-12-02
It does well but there is an issue. In some specific cases unit can pass same event several times and this query counts every such passing. I need to count every unit only once.
"Duplicated" records are in Event table. They have different dates and ids. Same for all records I need to count only once is flowid. Is there any simple way to achieve this?
Thank you for your time and answers!
To count each flowid only once, do count(distinct flowid), i.e.
SELECT
COUNT(distinct e.flowid) AS [count],
t.name AS [process],
CAST(DATEPART(YEAR, e.dtcr) AS VARCHAR) + '-' + CAST(RIGHT('0' + RTRIM(DATEPART(MONTH, e.dtcr)), 2) AS VARCHAR) + '-' + CAST(RIGHT('0' + RTRIM(DATEPART(DAY, e.dtcr)), 2) AS VARCHAR) AS [day]
FROM
...
It sounds like you need the first time that something passes the threshold. You can get the first time using row_number(). This can be tricky with the additional conditions on the query. This modification might work for you:
select sum(case when seqnum = 1 then 1 else 0 end) as cnt,
. . .
from (select e.*,
row_number() over (partition by eventid order by e.dtcr) as seqnum
from event e
where e.pass = 1 and -- only passed units
e.treenodeid IN (9036, 9037, 9038, 9039, 12594, 26330) and
e.dtcr >= '2015-12-01' AND e.dtcr < '2016-06-01'
) e join
. . .
You don't specify how the same event is identified for the duplicates. The above uses eventid for this purpose.
i have a view as below.
SELECT TOP (100) PERCENT 'SA' AS Doc_Type1, 'A' + SUBSTRING('000000', 1, 6 - LEN(CAST(dbo.companies.companyId AS varchar(10))))
+ CAST(dbo.companies.companyId AS varchar(10)) AS Client_ID, 1200 AS Bank_Nom, 0 AS Department, CONVERT(nvarchar(20),
dbo.invoices.invoiceDatePaid, 103) AS Cleared_Date, 'Bacs' AS Payment_type, dbo.invoices.invoiceId, dbo.invoices.invoiceTotal AS Value, '9' AS vat,
' ' AS bllank, 1 AS Ex_rate
FROM dbo.invoices INNER JOIN
dbo.companies ON dbo.invoices.invoiceCompanyId = dbo.companies.companyId
WHERE (dbo.invoices.invoiceDatePaid >= DATEDIFF(DAY, 1, CURRENT_TIMESTAMP)) AND (dbo.invoices.invoiceDatePaid < DATEDIFF(DAY, 0,
CURRENT_TIMESTAMP)) AND (dbo.companies.companyPaymentType = 3)
ORDER BY dbo.invoices.invoiceId DESC
In the Payment_Type column i want to add the SUM of the Value column to the word 'Bacs' so it reads 'Bacs £sum' to 2 decimal places. Could you help please, regards and thanks for all the help and suggestions already provided
I'm not very much clear to what exactly you need. You need complete sum of entire column to be displayed or in a group manner, but here is what you can try..Add the sum(Value) after converting it to varchar,which is necessary as two data types has to be varchar to concenate and group by all the remaining columns..something like this
....
,'Bacs'+cast(sum(dbo.invoices.invoiceTotal)
as varchar) AS Payment_type
...
group by all remaining columns
...
order by clause
I don't know whether it even close to what you need but it's just a try to help :-)