SSRS (report builder) sorting a row - sql

My requirement is I have to sort a row Month Wise, that is Jan, Feb, Mar etc right now it is not sorted.
I have tried writing query under query window order by case when...
I have tried writing query in expression of month field i.e.
IIF(Fields!Month_Y.Value = "Feb-19", 2,
IIF(Fields!Month_Y.Value = "Mar-19", 3,
IIF(Fields!Month_Y.Value = "Apr-19", 4,
IIF(Fields!Month_Y.Value = "May-19", 5,
IIF(Fields!Month_Y.Value = "Jun-19", 6,
IIF(Fields!Month_Y.Value = "Jul-19", 7,
IIF(Fields!Month_Y.Value = "Aug-19", 8,
IIF(Fields!Month_Y.Value = "Sep-19", 9,
IIF(Fields!Month_Y.Value = "Oct-19", 10,
IIF(Fields!Month_Y.Value = "Nov-19", 11, 12)))))))))))
I have wrote same IIF condition query in Tablix - Sorting expression field too.
But still it is not sorting the report month wise. if anyone can have a look and give the solution please.
Thank you in advance.

I understand from your question that you tried to use "case" on the "data set"
I have tried writing query under query window order by case when...
So the next thing that you need to do is:
Right-click on the column.
Go to "Shorting".
Press "Add".
Choose your "number" column(that you mapped - "Feb-19" etc.).
Choose your order method "Z-A" or "A-Z".
I simulated your case and it worked for me.
See the image below

Related

SQL query filter a row with a specific combination only

I am trying to query a table in which I have a specific condition, I do not want to query rows where Reference Category is Production and Issue is Sold.
In the above table, I want row 1,2& 4 only - How do I make such a query. If i do WHERE ReferenceCategory = 'Production line' AND Issue = 'Sold', it takes away row 4 as well.
http://sqlfiddle.com/#!18/f54f5b/1
I do not want to query rows where Reference Category is Production and [Issue is] Sold
You could simply phrase the conditions as follows:
WHERE NOT (ReferenceCategory = 'Production line ' AND Issue = 'Sold')
In your demo on DB Fiddle, this returns records 1, 2, 4.
Answered by #GMB:
SELECT *
FROM TransactionTable
WHERE NOT (ReferenceCategory = 'Production line' AND Issue = 'Sold')
For AX/D365 X++ user, the use of logical expression NOT(A and B) is not allowed in a X++ query range, therefore, transforming NOT(A and B) to its equivalent expression according to De'Morgans Law:
NOT(A and B) = (NOT A) OR (NOT B)
SELECT *
FROM TransactionTable
WHERE ReferenceCategory <> 'Production line' OR Issue <> 'Sold'**

Merging two queries that are the same BUT their GROUP BY?

So as the title implies, I have the same exact structure for two queries but I just need to change the grouping. I know I can do a union, however, to narrow the script, is there a way to associate both grouping in one query? For example:
SELECT shtuff FROM report_tickets WHERE something = something GROUP BY companies
//Query two
SELECT shtuff FROM report_tickets WHERE something = something GROUP BY ticket_id
Can I do?:
SELECT * FROM report_tickets WHERE something = something GROUP BY companies AND ticket_id
I know this doesn't work but in concept. Have the query take in account both groupings? ^^
I would need to add the following to line 30 from the linked code below, this may determine if it can work or not.
SUM(IF(ROUND((SELECT difference)) < 1, 1, 0)) AS zero_to_one,
SUM(IF(ROUND((SELECT difference)) BETWEEN 1 AND 8, 1, 0)) AS one_to_eight,
SUM(IF(ROUND((SELECT difference)) BETWEEN 8 AND 24, 1, 0)) AS eight_to_twentyfour,
SUM(IF(ROUND((SELECT difference)) > 24, 1, 0)) AS over_twentyfour,

Qlikview Set Analysis Average of the Minimum

I am trying to get the average of the minimum dates in a qlikview set analysis.
There is a set of data with an Initial Contact date, which is then followed by many Meeting Dates.
What I wanted to know was the average days from the InitialContact to the Min(MeetingDate) for all customers.
Ive had a look around the site and havnt seen anything comparable, I have also tried the online automatic set expression creator tool, however it doesnt have an example that works in this way.
All help is appreciated.
Cheers
Gary
I don't think a Set Analysis is what you are after. An aggr() should do what you want. I made this pretend data based on what you said
LOAD *,date(num(date#(IC,'YYYY/MM/DD'))) as InitialContact INLINE [
CustomerNo, IC
1, 2016/08/28
2, 2016/08/29
3, 2016/08/30
];
LOAD *,date(num(date#(MD,'YYYY/MM/DD'))) as MeetingDate INLINE [
CustomerNo, MD
1, 2016/08/30
1, 2016/08/31
2, 2016/08/31
1, 2016/09/01
2, 2016/09/01
1, 2016/09/02
2, 2016/09/02
3, 2016/09/02
1, 2016/09/03
2, 2016/09/03
3, 2016/09/03
2, 2016/09/04
3, 2016/09/04
3, 2016/09/05
3, 2016/09/06
];
And then I can use this expression
=avg(aggr(min(MeetingDate)-min(InitialContact),CustomerNo))
to get the average time from Initial Contact to First Meeting

Error while creating query as a Missing operator?

I am trying to extract data in a tabular format with different values for part-time and full-time, to get an output like this:
but my query generates this error:
syntax error missing operator
What operator is missing from this query?
SELECT
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
Count(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F") AS ["Full-time Undergraduate Enrollment"],
Count(IIf(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P",1,Null)) AS ["Part-time Undergraduate Enrollment"]
FROM BANINST1_SZVIRST
GROUP BY
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
BANINST1_SZVIRST.SZVIRST_TERM_CODE,
BANINST1_SZVIRST.SZVIRST_LEVL_CODE,
BANINST1_SZVIRST.SZVIRST_FULL_PART_IND
HAVING
(((BANINST1_SZVIRST.SZVIRST_TERM_CODE) In ("201020","201120","201220","201320","201420","201520","201620"))
AND ((BANINST1_SZVIRST.SZVIRST_LEVL_CODE)="01"));
I think you have 4 different conditions happening here that you are testing for:
Counts of people that are Full-Time
Counts of people that are Part-Time
Counts of people that are Graduate
Counts of people that are UnderGraduate
You are on the right track to use the iif() statement. I think that was from a previous question you asked a day or two ago. The iif() statements would be:
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F", 1, 0)) as [FullTime],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P", 1, 0)) as [PartTime],
SUM(IIF(SZVIRST_LEVL_CODE="01", 1, 0)) as [Graduate],
SUM(IIF(SZVIRST_LEVL_CODE="02", 1, 0)) as [UnderGraduate],
I changed the COUNT() to a SUM() just because it feels more natural since the IIF() is returning a 1 or a 0. You could change that back to a COUNT(Iif(<condition>, 1, null)) and it would fine too.
Checking for two conditions
If you want to combine a couple of conditions to get a count, the formula changes slightly.
For insstance, if you wanted a count of all Full-Time People that are also Under Graduates you could use:
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F" AND SZVIRST_LEVL_CODE="02", 1, 0)) AS [FullTimeUnderGraduates]
Here we put BOTH conditions INSIDE the first parameters of the IIF() formula. If both are TRUE, it returns a 1, then all those 1s gets summed up.
Lastly, if you are wanting to count/sum both Graduate and Under Graduates in your query, then you can't exclude them in your HAVING clause. So you'll need to remove the bit that reads:
((BANINST1_SZVIRST.SZVIRST_LEVL_CODE)="01")
Otherwise a test like
iif(BANINST1_SZVIRST.SZVIRST_LEVL_CODE="01", 1, 0)
will ALWAYS return a 1 and
iif(BANINST1_SZVIRST.SZVIRST_LEVL_CODE="02", 1, 0)
will ALWAYS return 0
Example
The following should run in your database and give you a good working example of the logic discussed above:
SELECT
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F", 1, 0)) as [FullTime],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P", 1, 0)) as [PartTime],
SUM(IIF(SZVIRST_LEVL_CODE="01", 1, 0)) as [Graduate],
SUM(IIF(SZVIRST_LEVL_CODE="02", 1, 0)) as [UnderGraduate],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F" AND SZVIRST_LEVL_CODE="02", 1, 0)) AS [FullTimeUnderGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P" AND SZVIRST_LEVL_CODE="02", 1, 0)) AS [PartTimeUnderGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F" AND SZVIRST_LEVL_CODE="01", 1, 0)) AS [FullTimeGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P" AND SZVIRST_LEVL_CODE="01", 1, 0)) AS [PartTimeGraduates]
FROM BANINST1_SZVIRST
GROUP BY
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
BANINST1_SZVIRST.SZVIRST_TERM_CODE,
BANINST1_SZVIRST.SZVIRST_LEVL_CODE,
BANINST1_SZVIRST.SZVIRST_FULL_PART_IND
WHERE BANINST1_SZVIRST.SZVIRST_TERM_CODE IN ("201020","201120","201220","201320","201420","201520","201620")

NHibernate - ICriteria for two tables?

I'm having a heck of a time creating the ICriteria for two tables.
The SQL I am trying to mimic is below.
Is there anyway to do this?
I've been trying CreateAlias, Subqueries, and a bunch of other stuff But I always end up with errors.
I have tried posting this on the nhusers Google group, but not getting much help.
Thanks.
Kim
SELECT *
FROM Echo_File_status efs, Data_DELETION_PARAMETER ddp
WHERE
efs.EFS_PRODUCT_CODE = DDP.DDP_PRODUCT_CODE(+)
AND
DDP.DDP_PROCESS_TYPE = 'D'
AND
( ( trunc(nvl(efs.efs_file_create_date, sysdate)) > sysdate - dp.DDP_DAYS_ON_LINE ) or
( efs.efs_status_code != 'ACKED' ) )
ORDER BY efs.efs_product_code, decode(efs.efs_status_code, 'READY', 1, 'TRANS', 2 , 'FAERR', 3, 'FCERR', 4, 'PRERR', 5, 'TRERR', 6, 'PREP', 7, 'PRCOM', 8, 'FCREA', 9 , 'TRCOM', 10, 'ACKED', 11, 1),
efs.efs_file_create_date DESC
Why use icriteria while Hql would be easy to use? Join the objects on that code property.
My personal opinion on this kind of problem, is that you should just keep writing expressions like that in pure SQL, since it will only be worse to read and maintain using the NHibernate criteria API.
As long as you have test coverage on the query, you can safely hide that implementation detail away.