crystal reports table source difficulty with user defined functions - sql-server

I have the following Query:
SELECT *
FROM tbl_Muffins
WHERE OvenLoadId IN (
SELECT OvenLoadId
FROM tbl_Muffins
WHERE OrderId = ?
GROUP BY OvenLoadId
)
ORDER BY OvenLoadId, LocationNumber ASC
The idea of the query is that I want to specify an OrderId, and I want all Oven Loads that have items from that order in them, as well as ALL OTHER ITEMS in those loads, even though they could be from other orders.
The query works as expected, but I'm not able to use it for my Crystal Report I've written it for.
I have put this query into a User Defined Function, however I'm unable to use a call to that function as a table source in my Crystal Report. I am using Visual Studio 2003 (I know it is old, the client refuses to upgrade).
What am I doing wrong?
Thanks,
jnsohnumr

From version 9 of Crystal Reports onwards, it became possible to report from custom queries using Crystal's "Add Command" functionality.
There is a description of adding a parameter to a command query here.

Related

SQL Server SSMS Default SELECT TOP <n> ROWS from SQL can I change the Order as a Default setting?

I get that we can right-click and SELECT TOP <n> ROWS from any given table in SSMS, is there any way to change this default script to that it also orders the records with ORDER BY 1 DESC?
What I would really like to increase my productiveness is
Right-click - SELECT TOP <n> ROWS ORDER BY 1 DESC
Or do I have to have a snippet so once the records are returned that I then have to paste a the snippet in?
Or even bind a stored procedure to a keyboard shortcut?
Many thanks
No, there is no way to customize what text appears in the query window when you use the menu options in the GUI. This code is buried somewhere in the bowels of the executable and/or DLLs.
I would suggest using a snippet instead of the point-and-click stuff. Or if you really want to customize the UI, see if any existing SSMS add-in does this, or write your own. It might be easier these days to build such a thing for Azure Data Studio, though.

What is the best way to cross reference two SQL Views in Report Builder?

I'm new to SQL queries and need to build a custom report in Microsoft SQL Report Builder 3.0. The data source is a SCCM database. I need help with understanding the best approach to achieve the following:
We need to cross reference if a computer exist in two Views, if so show that name in the report.
InputParameter1 = "Please select a View"
InputParameter2 = "Cross reference with this other View"
If I know the names of the Views beforehand I have a query to get what I need from the SQL server, but I need to create a parameter-based report where you select two Views dynamically and the report cross reference them for you and present which computers exists in both Views.
This is the query I can use for a static result. v_CM_RES_COLL_CMS0020B and v_CM_RES_COLL_CMS000D1 are examples of names of possible Views, until I can solve the parameter issue in Report Builder:
SELECT v_GS_SYSTEM.Name0
FROM v_GS_SYSTEM
WHERE Name0 IN
(SELECT Name from v_CM_RES_COLL_CMS0020B)
AND Name0 IN
(SELECT Name from v_CM_RES_COLL_CMS000D1)
I don't know how to proceed in how to make the above query into a parameter report in Report Builder. Somehow I need to change v_M_RES_COL_CMS00### to what ever the user inputs to the parameters. Does anyone know how? Any help is greatly appreciated.

SSRS - missing data in the table in my report even though no missing data in sql server

I have a stored procedure returning data like:
Id Name fromTable
1 Alison Table1
2 Gary Table2
3 Jack Table1
4 John Table3
by the code:
Select Id, Name, fromTable='Table1' from Table1
union
Select Id, Name, fromTable='Table2' from Table2
union
Select Id, Name, fromTable='Table3' from Table3
I created a report in SSRS 2008, created Dataset1 which is connected to this SP and I am inserting a table to my SSRS report which is connected to Dataset1. However, here I only see the data coming from Table1 (Alison and Gary). I cannot see the data coming from Table2 and Table3. I could not understand why it is happening and how to fix it, because seems like query is working well in the SQL Server 2008. Any help would be appreciated.
Hey I will do couple of things here.
I will run my query in query designer in SSRS(Visual studio) after clicking refresh fields. If you are not getting all data here you have an issue in your query.
I will delete rdl data file, to make sure you are not holding any cache.
I tried the sample data you gave i can see all the data in my SSRS 2008. i will suggest you delete the report and re-create it making sure that the report is pointed to the correct data source
First, validate your data in sql server. Sometimes these SP's do not do exactly what we intended them to do, although your query looks simple enough I would still double check. If that output is what you need then I would suggest just rewriting your ssrs ensuring that your datasource is correct and everything else is jiving. SSRS is super clunky!!!
This is very handy solution to add to your VS:How to add Clear Cache from VS/Tools
to test cache issue, make any notable change in SQL to see if it's coming through.
to test any rdl issues made any notable change in let say Header and run report
if those 2 test passed OK, then check dataset properties (Filters)
if this passed then check Tablix properties (filters), then tablix raw visibility
Check dataset properties (Query type: make sure if it's sp name = corrrect).
Check data SOURCE ! so it points to the right server / db
Is this yours rdl or somebody's else?
J

Scheduling SSRS with parameters

Currently, I have a report on SSRS ( SQLServer 2008R2) and accept a invoice number as a parameter. The report will generate the information related to this invoice in 1 report. So, 1 invoice 1 report. If I need to generate 2 invoices, I need to run twice.
I would like to schedule it and generate reports automatically once the invoice appears in the database and save the output as PDF for each in a unique file name.
Just wonder what's the best option for me to do it
1) Use SSIS. Create a For..Loop to execute a SQL statement to return all invoices that fulfills the criteria and then call SSRS report.
2) In SSRS, there's a subscribe option but I can't find any way I can pass in the parameter automatically and for multiple times. Or some configuration that I missed out ?
Hope you can provide me some ideas. Thanks.
both 1 and 2 would work. To me, I think 2 is better.
2) In SSRS, there's a subscribe option but I can't find any way I can pass in the parameter automatically and for multiple times. Or some configuration that I missed out ?
I found this on Microsoft site which covers how to pass in parameter value to report. Hope it is helpful.
https://msdn.microsoft.com/en-us/library/ms166561(v=sql.105).aspx

Use a query to sort a report in MS Access

I am a beginner in MS Access and am currently stuck with a problem.
I have a database about movies and I'm currently creating a list of all the movies that I want to have sorted by popularity.
To determine the popularity of a movie I have a different table that has a history of what my customers have watched, every movie they have watched is a seperate entry in that table.
I have created a report that has 3 things, the title of the movie, the ID of the movie and a button to watch that movie. But I want to sort the report to show the movies with the most viewers first.
I have created this code in SQL Management Studio which works exactly like I want too:
SELECT [Film].[Titel], [Film].[Film_ID], COUNT([historie].[Film_ID]) as timesWatched
FROM [Film] INNER JOIN [historie] on [Film].[Film_ID] = [historie].[Film_ID]
GROUP BY [Film].[Titel], [Film].[Film_ID]
ORDER BY timesWatched DESC
I'm not that good with Access yet and have no idea how I can use this query to sort the report, I tried putting it in the row source (with everything on one line) in the report properties, which didn't work.
I hope someone has an idea on what to do, is it possible to use this query somewhere or should I use something else than a Report?
Thanks in advance for the answers!
If I'm not wrong..
First create the Query in ACCESS (Create tab -> query) There you will be able to create that query, save it, then go to your report and set its source to this query, the last step will be to set each textbox/label source to the query field, I mean if you have a textField in your report where you want to diplay "movieName", you must select data source from this text box and choose between all fields in your query (in this case, and following a good practice, let's say the field is called movieName too).

Resources