SQL Server query to Crystal Reports - sql-server

I am trying to move reports that currently run in SQL Server to Crystal Reports.
Essentially the statement I want to reproduce is:
SELECT DATEPART(DD,DATE), COUNT(*)
WHERE FOO = 'BAR'
GROUP BY DATEPART(DD,DATE)
Count the occurrence of records that match a criteria, grouped by date.
I have used the Selection Expert to generate a equivalence relation (to evaluate the records) and would like to use the datepart function in a group by statement. I have gotten the GROUP BY selection expert to group by date - but it is the full timestamp (SS:HH:DD:MM) not by specific day i.e. March 1 2010.
I am sure there is a way to achieve what I want but have yet to find a tutorial explaining this scenario.
Any help you could lend would be appreciated

As with any other SDK/Language, there are many ways to do this. Here is the first one that I can think of:
Get the raw data into Crystal. (Sounds like you already did this)
In Crystal, make a new formula, call it "GroupByDate". In the formula editor, enter:
datepart("yyyy-mm-dd",{mytable.mydatefield})
Go into the Group Expert. Group your report by GroupByDate.
Make a new formula, call it "AddMe". In the formula editor, enter:
iif({mytable.foo="bar",1,0)
Drag & drop your AddMe formula into the details section. Right-click on it to Insert->Summary. Set your summary location as the group footer.
Preview your report and you should see the total counts in every group footer. To simplify the appearance of the report, you can also suppress the display of the detail and grouper header sections.
Again, there are many ways to do this. You can also get creative with a Running Total function. The Crystal Formula Editor has very useful help files. Use the Functions pane to select a function, press F1, and you'll get criteria, examples, etc.

Related

SQL Report Builder 3.0 - How to group to get results (screenshots)

Here is the result set I want to get (from old report): Customer parameter is set to select all, in case anyone had questions about that field.
.....
As you can see, the report works so that each customer is grouped under a given salesperson and a total tally is at the bottom.
My problem is that this is the result I keep getting when trying to replicate this result in my new report (values aside, I know I can clean those up in the properties):
How do I do the grouping so that my subtotals, per customer, are reflected in a grand total at the bottom (in yellow)? I can do this easily in SQL, but getting it to work in report builder is what's driving me nuts lol

Ssrs reports Windows 2008

I'm fairly new to SQL and I have been issued my first report to build. I have written an SQL query to give me a set of results that I would like to publish in a report.
I have unioned about 20 small queries all containing the correct amount of columns. One column is a misc column with about 15 different descriptions in (this is what I want to count).
I have uploaded my data set and now want to be able to choose a cell in my report to bring back a certain description.
At the minute I'm using
=count(fields!misc.values)
and it's giving me the whole count, about 200.
I would like to know if there is any kind of "where clause" (filter) which I can use to state which description results I want to bring back.
You can use am expression to count the misc.value you need. It will work like a count using a where clause:
=Sum(iif(Fields!misc.Value ="Some description",1,0))
Example:
For count the FSMethod with MethodOne as value I used this expression:
=Sum(iif(Fields!FSMethod.Value ="MethodOne",1,0))
Note the expression sums by 1 if the FSMethod.Value is MethodOne.
For count the rows with FSMethod column with MethodTwo value.
=Sum(iif(Fields!FSMethod.Value ="MethodTwo",1,0))
Let me know if this can help you.

SSRS or SQL - DateDIFF on the same column with certain criteria

I have a report I created in SSRS. I have it grouped by a column. The Column it is grouped by there are description, details and a date for each.
I want to try and find a datediff between two descriptions for the group but I can't seem to get it right.
I tried to do ::
=DateDiff(dateinterval.Minute,(Fields!date.Value=(Fields!description.Value="description1")),(Fields!date.Value=(Fields!description.Value="description2")))
but it errors out. any idea ? I can supply the code or screenshot if it doesn't make sense.
Try this:
=DateDiff(DateInterval.Minute
,lookup("description1",Fields!description.Value,Fields!date.Value,"DataSet1")
,lookup("description2",Fields!description.Value,Fields!date.Value,"DataSet1"))
Let me know if this was helpful.

Crystal Reports- use other records for condition?

I am somewhat new to crystal reports and the syntax involved, and cannot seem to find the specifics by searching.
The problem is,
I need to check a condition of another record (linked as in image) for when Op No=10 in table Route, I must then check the Date Complete of this record in table WO Route Schedule for the same OP (see image for how they are linked) with a date input by user when the report is ran.
Table links
The jist is, im trying to show the font of a field in red when Date Complete>=FDate (user) (FOR OP 10), but since the actual list i am generating is of OPs that are not 10, I cannot seem to point crystal to look for when Op No=10, which is linked to the current OP by Route_ID and Work Order_ID! I have been trying many If statements, as well as using a case statement for when Op_No=10, but to no avail.
As a novice, I am not entirely sure of what other information is needed. Hopefully the images help explain my motive, but please ask for more info if you think this problem can be solved.
Regards
EDIT: More context if it helps (first comment)
Yeah it's hard to explain without overdoing the details, but each work order (WO) has around 100 operations (OPs). Now, crystal reports generates a list of OPs which are still active on the shop floor, but firstly it must check if a certain OP has been completed FOR THAT work order, which then produces a field with red font for when OP number 10 is completed. Now, if I was to simply put If {WO_Route_Schedule.Date_Complete}>={?FDate} , it would use the current OPs complete date, not OP No 10 for that Work order!
ok try below solution:
Place below condition in record selection formula .
{WO_Route_Schedule.Date_Complete}>={?FDate}
to find record selection formula go to File--> selectin formula ---> record
Place the op field OP No in detail section,
Now right click the op no field go to Format field ---> Tab Font ---> formula editor of color
write below condition there
if Op No=10
then crRed
else crBlack
Let me know how it goes

How do I get around the Sum(First(...)) not allowed limitation is SSRS2005

The problem that I have is SQL Server Reporting Services does not like Sum(First()) notation. It will only allow either Sum() or First().
The Context
I am creating a reconciliation report. ie. what sock we had a the start of a period, what was ordered and what stock we had at the end.
Dataset returns something like
Type,Product,Customer,Stock at Start(SAS), Ordered Qty, Stock At End (SAE)
Export,1,1,100,5,90
Export,1,2,100,5,90
Domestic,2,1,200,10,150
Domestic,2,2,200,20,150
Domestic,2,3,200,30,150
I group by Type, then Product and list the customers that bought that product.
I want to display the total for SAS, Ordered Qty, and SAE but if I do a Sum on the SAS or SAE I get a value of 200 and 600 for Product 1 and 2 respectively when it should have been 100 and 200 respectively.
I thought that i could do a Sum(First()) But SSRS complains that I can not have an aggregate within an aggregate.
Ideally SSRS needs a Sum(Distinct())
Solutions So Far
1. Don't show the Stock at Start and Stock At End as part of the totals.
2. Write some code directly in the report to do the calc. tried this one - didn't work as I expected.
3. Write an assembly to do the calculation. (Have not tried this one)
Edit - Problem clarification
The problem stems from the fact that this is actually two reports merged into one (as I see it). A Production Report and a sales report.
The report tried to address these criteria
the market that we sold it to (export, domestic)
how much did we have in stock,
how much was produced,
how much was sold,
who did we sell it to,
how much do we have left over.
The complicating factor is the who did we sell it to. with out that, it would have been relativly easy. But including it means that the other top line figures (stock at start and stock at end) have nothing to do with the what is sold, other than the particular product.
I had a similar issue and ended up using ROW_NUMBER in my query to provide a integer for the row value and then using SUM(IIF(myRowNumber = 1, myValue, 0)).
I'll edit this when I get to work and provide more data, but thought this might be enough to get you started. I'm curious about Adolf's solution too.
Pooh! Where's my peg?!
Have you thought about using windowing/ranking functions in the SQL for this?
This allows you to aggregate data without losing detail
e.g. Imagine for a range of values, you want the Min and Max returning, but you also wish to return the initial data (no summary of data).
Group Value Min Max
A 3 2 9
A 7 2 9
A 9 2 9
A 2 2 9
B 5 5 7
B 7 5 7
C etc..
Syntax looks odd but its just
AggregateFunctionYouWant OVER (WhatYouWantItGroupedBy, WhatYouWantItOrderedBy) as AggVal
Windowing
Ranking
you're dataset is a little weird but i think i understand where you're going.
try making the dataset return in this order:
Type, Product, SAS, SAE, Customer, Ordered Qty
what i would do is create a report with a table control. i would set up the type, product, and customer as three separate groups. i would put the sas and sae data on the same group as the product, and the quantity on the customer group. this should resemble what i believe you are trying to go for. your sas and sae should be in a first()
Write a subquery.
Ideally SSRS needs a Sum(Distinct())
Re-write your query to do this correctly.
I suspect your problem is that you're written a query that gets you the wrong results, or you have poorly designed tables. Without knowing more about what you're trying to do, I can't tell you how to fix it, but it has a bad "smell".

Resources