How to group ssrs report with a group - ssrs-2008

I have a resultset from stored procedure.
Id ShortName yValue xValue Sum
1 A Place1 -3 10.02
1 B Place1 -3 9.5
1 Diff Place1 -3 .52
2 C Place2 -3 7.62
2 D Place2 -3 8.50
2 Diff Place2 -3 -0.88
I need to display this result in SSRS as shown below
A B Diff
Place1 10.02 9.5 .52
C D Diff
Place2 7.62 8.50 -.88.
Could you please suggest

I got the solution for this and I am glad to share with you.
To separate a report into two, we need a column which distinguish them. Here i have Id column which distinguish two reports. So I have created a row group bu the following steps.
Row Groups> Right click and select Add group>Parent group> Group by> Select Id(column name) .Done.
Then press F4 for properties ,expand Group > expand PageBreak > set Break location as Start.
This will give the reports in different worksheet. If you need to set custom worksheet name, then set in PageName property.
Hope it will help you.

Related

Answer Set Programming: how to assign students to a group such that no two students who dislike each other are in a same group

I am a beginner to Answer Set Programming. I want to group all students in a different groups such that:
1. Each group has 3 to 4 students
2. No two students who dislike each other are in the same group.
3. And we can not assign same student to different groups.
I have written like:
%suppose there are total 6 students
student(1..6).
%suppose there are 2 groups
group(1..2).
%1 and 4 like each other, 4 and 5 dislike each other
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
I have added the constraint for how many students each group can contain but have got no clue about how satisfy other two conditions.
Your help will be greatly appreciated. Thanks.
Try this:
student(1..6).
group(1..2).
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
%no two students who dislike each other are in the same group
:-in(X, G1), in(Y,G2), dislike(X,Y), group(G1), group(G2), G1==G2.
%each student should be assigned to only one group
1{in(S,G): group(G)}1 :- student(S).
#show in/2.

Crystal Report Cross Tab Calculated Member as text

I'vre created a cross tab report with 2 calculated Member to be able to have the difference between 2 column and the percentage of this difference in CR 2011. What I want to achieve is to create a new column that will display a test depending on the difference value.
Here is a example:
Col1 Col2 Difference Percentage Action
200 0 -200 100 DROPPED
100 100 0 0
0 300 300 100 ADDED
How can create this action column. Calculated member only want some amount value so I cannot output a text in the formula.
Thanks in advance for your help
I finally found the solution.
I can use the Display string formula in the Format Field properties (Common Tab). Here I just check the column and return the string I want otherwise I just format the number.
IF GetColumnGroupIndexOf(CurrentColumnIndex) = 1
AND CurrentColumnIndex =4 THEN
IF GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex) =2 THEN "DROPPED"
ELSE "ADDED"
ELSE
ToText( GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex),2,",")

Postgres bitmask group by

I have the following flags declared:
0 - None
1 - Read
2 - Write
4 - View
I want to write a query that will group on this bitmask and get the count of each flag used.
person mask
a 0
b 3
c 7
d 6
The result should be:
flag count
none 1
read 2
write 3
view 2
Any tips would be appreciated.
For Craig
SELECT lea.mask as trackerStatusMask,
count(*) as count
FROM Live le
INNER JOIN (
... --some guff
) lea on le.xId = lea.xId
WHERE le.xId = p_xId
GROUP BY lea.mask;
SQL Fiddle
select
count(mask = 0 or null) as "None",
count(mask & 1 > 0 or null) as "Read",
count(mask & 2 > 0 or null) as "Write",
count(mask & 4 > 0 or null) as "View"
from t
Simplest - pivoted result
Here's how I'd approach it:
-- (after fixing the idiotic mistakes in the first version)
SELECT
count(nullif(mask <> 0, True)) AS "none",
count(nullif(mask & 2,0)) AS "write",
count(nullif(mask & 1,0)) AS "read",
count(nullif(mask & 4,0)) AS "view"
FROM my_table;
-- ... though #ClodAldo's version of it below is considerably clearer, per comments.
This doesn't do a GROUP BY as such; instead it scans the table and collects the data in a single pass, producing column-oriented results.
If you need it in row form you can pivot the result, either using the crosstab function from the tablefunc module or by hand.
If you really must GROUP BY, explode the bitmask
You cannot use GROUP BY for this in a simple way, because it expects rows to fall into exactly one group. Your rows appear in multiple groups. If you must use GROUP BY you will have to do so by generating an "exploded" bitmask where one input row gets copied to produce multiple output rows. This can be done with a LATERAL function invocation in 9.3, or with a SRF-in-SELECT in 9.2, or by simply doing a join on a VALUES clause:
SELECT
CASE
WHEN mask_bit = 1 THEN 'read'
WHEN mask_bit = 2 THEN 'write'
WHEN mask_bit = 4 THEN 'view'
WHEN mask_bit IS NULL THEN 'none'
END AS "flag",
count(person) AS "count"
FROM t
LEFT OUTER JOIN (
VALUES (4),(2),(1)
) mask_bits(mask_bit)
ON (mask & mask_bit = mask_bit)
GROUP BY mask_bit;
I don't think you'll have much luck making this as efficient as a single table scan, though.

Crystal Report Grouping issue

I have a table like this:
Prod Unit Name
A 1 X1
B 2 X2
A 3 X3
B 4 X4
Now I am grouping it by Prod column.
I want all Distinct Unit column values in group Header, something like this:
Group header: **PROD**: A **Unit**:1,3
Detail: X1
X3
Group Header: **PROD**: B **Unit**:2,4
Details: X2
X4
Please let me know any possible way to achieve this. Thanks in advance
Yes, this can be done.
Insert a group on Unit
Suppress GH1 and GF1
Create a manually, running-total field to serialize the Unit (there are so many examples of this, that I won't repeat the process)
Add a text field with the text 'PROD: '; insert the G1-name field into the text field
Do the same for the 'Unit' field; insert the formula that holds the serialized values

Postgresql sorting mixed alphanumeric data

Running this query:
select name from folders order by name
returns these results:
alphanumeric
a test
test 20
test 19
test 1
test 10
But I expected:
a test
alphanumeric
test 1
test 10
test 19
test 20
What's wrong here?
You can simply cast name column to bytea data type allowing collate-agnostic ordering:
SELECT name
FROM folders
ORDER BY name::bytea;
Result:
name
--------------
a test
alphanumeric
test 1
test 10
test 19
test 20
(6 rows)
All of this methods sorted my selection in alphabetical order:
test 1
test 10
test 2
test 20
This solution worked for me (lc_collate: 'ru_RU.UTF8'):
SELECT name
FROM folders
ORDER BY SUBSTRING(name FROM '([0-9]+)')::BIGINT ASC, name;
test 1
test 2
test 10
test 20
select * from "public"."directory" where "directoryId" = 17888 order by
COALESCE(SUBSTRING("name" FROM '^(\d+)')::INTEGER, 99999999),
SUBSTRING("name" FROM '[a-zA-z_-]+'),
COALESCE(SUBSTRING("name" FROM '(\d+)$')::INTEGER, 0),
"name";
NOTE: Escape the regex as you need, in some languages, you will have to add one more "\".
In my Postgres DB, name column contains following, when I use simple order by name query:
1
10
2
21
A
A1
A11
A5
B
B2
B22
B3
M 1
M 11
M 2
Result of Query, After I have modified it:
1
2
10
21
A
A1
A5
A11
B
B2
B3
B22
M 1
M 2
M 11
You may be able to manually sort by splitting the text up in case there is trailing numerals, like so:
SELECT * FROM sort_test
ORDER BY SUBSTRING(text FROM '^(.*?)( \\d+)?$'),
COALESCE(SUBSTRING(text FROM ' (\\d+)$')::INTEGER, 0);
This will sort on column text, first by all characters optionally excluding an ending space followed by digits, then by those optional digits.
Worked well in my test.
Update fixed the string-only sorting with a simple coalesce (duh).
OverZealous answer helped me but didn't work if the string in the database begun with numbers followed by additional characters.
The following worked for me:
SELECT name
FROM folders
ORDER BY
COALESCE(SUBSTRING(name FROM '^(\\d+)')::INTEGER, 99999999),
SUBSTRING(name FROM '^\\d* *(.*?)( \\d+)?$'),
COALESCE(SUBSTRING(name FROM ' (\\d+)$')::INTEGER, 0),
name;
So this one:
Extracts the first number in the string, or uses 99999999.
Extracts the string that follows the possible first number.
Extracts a trailing number, or uses 0.
A Vlk's answer above helped me a lot, but it sorted items only by the numeric part, which in my case came second. My data was like (desk 1, desk 2, desk 3 ...) a string part, a space and a numeric part. The syntax in A Vlk's answer returned the data sorted by the number, and at that it was the only answer from the above that did the trick. However when the string part was different, (eg desk 3, desk 4, table 1, desk 5...) table 1 would get first from desk 2. I fixed this using the syntax below:
...order by SUBSTRING(name,'\\w+'), SUBSTRINGname FROM '([0-9]+)')::BIGINT ASC;
Tor's last SQL worked for me. However if you are calling this code from php you need add extra slashes.
SELECT name
FROM folders
ORDER BY
COALESCE(SUBSTRING(name FROM '^(\\\\d+)')::INTEGER, 99999999),
SUBSTRING(name FROM '^\\\\d* *(.*?)( \\\\d+)?$'),
COALESCE(SUBSTRING(name FROM ' (\\\\d+)$')::INTEGER, 0),
name;