I have 2 data sets that have the common column VNO. Now I want to get the report in ssrs like
VDate, Count('') from B for Vdate, Count('') from A for Vdate
Can anyone help me with the way, I tried the lookup but not able to get this output.
Note: I cannot join these two tables in SQL as these 2 tables are on separate instances and they are not connected and don't have permission to do so.
You need to use LOOKUPSET() . This returns an array which you can then check the length of like this
=LookupSet(Fields!InvoiceDate.Value, Fields!VDate.Value, Fields!VNO.Value, "DataSetB").Length
The 3rd argument is the returned value but as you are only getting a count, it does not matter what we return there. DataSetB is the case sensitive name of your second dataset.
Related
I have a table with two columns hora_entrada and hora_saida and when running this select statement:
select hora_entrada, hora_saida
from Controlo_de_Entrada_saidas
it shows this result:
What I want to do is to combine these two columns into one that if Hora_saida = "Não saiu", it shows the data in hora_entrada but if hora_saída has an actual hour in there, it shows the data in hora_saida instead.
So basically this should be my result:
I don't know if I'm making myself clear, I actually don't even know where to start or if its even possible but any help would be appreciated.
Try using a CASE expression:
SELECT
hora_entrada,
hora_saida,
CASE WHEN hora_saida = 'Não saiu'
THEN hora_entrada ELSE hora_saida END AS new_column
FROM yourTable;
This logic assumes that any value in the hora_saida column which is not Não saiu is a valid timestamp. If not, then we could add additional logic to check for this as well.
If you are open/able to changing your data model, you might want to consider just storing NULL values for the missing data. SQL Server (and most other databases as well) has a built-in function COALESCE, which can be used to replace NULL with a backup value. This would avoid needing to use a lengthy CASE expression as you see above.
I'm learning MSBI tools and came across a requirement in SSRS wherein we need to constrain report parameter 2 with parameter 1.
i.e. if I have parameters setup on [AdventureWorks2008R2].[HumanResources].[Department] table and if I select "Group Name" (Parameter 1) as "Manufacturing" then the "Name" (Parameter 2) drop down should populate only relevant values("Production" and "Production Control") specific to selected parameter 1 value ("Manufacturing")
I have been exposed to OBIEE tool and know that under this tool we have a "constrain" option under Prompts to achieve the same.
I could come up with the following solution under SSRS:
Created two datasets for each of the parameters with below queries.
Parameter 1 (GroupName)
SELECT DISTINCT GroupName
FROM HumanResources.Department
Parameter 2 (DeptName)
SELECT Name
FROM HumanResources.Department
WHERE (GroupName = #GroupName)
This worked. However if there are 5 such parameters which are to be constrained then with this solution I would have to create 5 such datasets and accordingly build the WHERE clause for each parameter.
Is there a better solution to achieve the same (there should be..)
I'm new to SSRS and therefore would appreciate any pointers here.
Thanks!
What you are talking about is called "Cascading Parameters" and they are implemented exactly as you did. You can read about them here:
Adding Cascading Parameters (SSRS)
So if you need to implement 5 of such parameters you have to write 5 queries for 5 datasets each one containing WHERE referencing parameter defined in previous dataset
I know there are existing questions regarding to this error. but my situation looks different!
I'm creating a SSRS2012 report that can manually input UserIDs number (such as 15, 130, etc..) as the IC_ID. I want to ensure when input is null, report can display all IC_ID. I tried two method to approach it.
Data source: Oracle Sql Developer, table:IC, column: IC_ID datatype:NUMBER
Parameter: UserIDs, datatype: Integer, allow null value.
------------Method 1:---------------
SSRS dataset query, I've tried:
select * from IC
where IC_ID=to_number(COALESCE(:UserIDs, IC_ID))
select * from IC
where IC_ID=to_char(COALESCE(:UserIDs, IC_ID))
select * from IC
where IC_ID=COALESCE(:UserIDs, IC_ID)
But all failed with same error: NUMBERORA-00932 expected CHAR got NUMBER. When I run them in Oracle database, show same error as above. So I guess the problem is how to make data type consistent, column IC_ID data type is NUMBER, if I set parameter UserIDs as Integer, why still not consistent?
PS:when I only use query as:
**select * from IC where IC_ID=(:UserIDs)**
no matter I set parameter datatype to text or integer, the report works fine and display info of whatever IC_ID value I manually input. But it didn't show data when parameter is null!
---------Method 2---------
SSRS dataset query, I've tried:
select * from IC
where IC_ID=(:UserIDs) or (:UserIDs) IS NULL
failed with error: attempted to read or write protected memory. this is often an indication that other memory is corrupt. When I run this query in Oracle, it run well with not error, no matter I pass a number or null to (:UserIDs). So I guess the problem is how to use (:UserIDs) TWICE in SSRS dataset query.
I'm very sure it's not because of memory limit, because this report run well displaying all IC_ID info when there is no parameter at all. It seems it doesn't allow one parameter to show up more than once in dataset query, whenever I tried something like: select * from IC where IC_ID=(:UserIDs) AND IC_SubID=(:UserIDs), it will fail with memory corrupt error.
But it works fine if (:UserIDs) only show up once in query.
---------Method 3----------------
Some posts said in order to display all info when parameter is null, we can add a list of all IC_ID as the default value of parameter. I don't think it works for this case, because my dataset query is actually very complex, starting with a long cte. It will be too complex and slow to add this whole cte query into the list as default value.
I would appreciate if anyone could give some help of how to solve any of above errors, or tell me other ways to display all info while parameter is null!
Thank you
Isn't possible to cast the parameter as an integer? Like cast((:UserIDs as int)) (or maybe cast as a char). Don't know if this helps but i would expect that the datatype is always the same.
Or you could maybe use
(:UserIDs) in (case when (:UserIDs) is null then (select UserIDs from table) else (:UserIDs) end)
I have a parameter question in SSRS . I currently have 3 parameters set up, Permanent Employee then select P, Temporary Employee then select T and Partner Employee then select P.
So the user selects parameter one , Permanent and then selects parameter two, Temporary and then the third parameter, Partner.
This then feeds into my sql query to return the result set....like below .
AND (A.[EMPTYPE]=#EmploymentP1
OR A.[EMPTYPE]=#EmploymentP2
OR A.[EMPTYPE]=#EmploymentP3 )
So the question if I wanted one parameter that will allow one or more of the values to be selected, Permanent , temporary or Partner
to be selected. How to do this ? So a multi value parameter in SSRS. But how do you then feed those results into the query is the bit I dont understood yet. Any ideas?
If for example your single parameter was #Employment, you would use:
WHERE A.[EMPTYPE] IN (#Employment)
SSRS Internally parses this to valid syntax before sending the query to the database.
Please visit http://www.stumbleupon.com/
It asks you what interests you.
I would have a similar thing on my website except I would need to have 4 of such non-identical blocks. When a user has not selected anything in a section, it means s/he has selected all of them. 1 of these blocks would have around 10 options while the other 3 would have 2-3 options each.
How do I pass what all a user has selected to SQL Server 2008? Please note I would have 4 sets of multiple params, and these 4 sets are basically 4 different columns in the row all containing integer id's. If and only if one param per section was passed, I would have done something like
select * from table where column1 = #param1, column2 = #param2 and so on.
but that is not the case, because a user could pass multiple values for #param1 and so on.
I can get this done, but I want to know the most efficient way.
If my post is not clear, please let me know.
EDIT:
Basically, if I am storing articles in the database, I have 4 columns in the row, each integer. And I want to query these articles based on these 4 columns, but the catch is to pass the multiple values for these columns NOT just one value per column.
If your client language supports it, you should look into table value parameters:
http://www.sqlteam.com/article/sql-server-2008-table-valued-parameters
if you can't use those, look into one on Arrays and Lists in TSQL:
http://www.sommarskog.se/arrays-in-sql.html
this is a very comprehensive list of dynamic search conditions in TSQL:
http://www.sommarskog.se/dyn-search.html
this may also help:
Sane/fast method to pass variable parameter lists to SqlServer2008 stored procedure
Try dumping all parameter values into the XML, then pass it to SQL Server, then parse it in the query.
Won't such a query work in this case?
SELECT *
FROM TABLE
WHERE COLUMN1 IN ( #param11, #param12, #param13 )
AND COLUMN2 IN ( #param21, #param22, #param23 )
and so on.