I have report where I am using that stored procedure to create a report using SSRS. The report currently show data like below (it has more additional columns) :
What I want is at the backend (stored procedure level or in SSRS) want the filter the data for product_type A only, but I want to show the amount associated with the product type F in a new column as below:
Can anyone help to achieve this please?
A simple LEFT JOIN with the same table will do the work
SELECT t1.INVOICE_NO,t1.PRODUCT_TYPE,t1.AMOUNT,t2.AMOUNT AS FEE_AMOUNT
FROM tbl t1
LEFT JOIN tbl t2 ON t1.INVOICE_NO=t2.INVOICE_NO AND t2.PRODUCT_TYPE='F'
WHERE t1.PRODUCT_TYPE='A'
you can also use matrix to achieve the same on ssrs side. In this case your trade off is none i.e. doing pivot on sql side and then rendering the data in ssrs table VS leaving data as is in sql and using matrix to pivot the data.
Related
I have a problem in Power BI with DAX, i want to do SQL joins in Dax , i made my data modelling with my tree tables
Table 1
enter image description here
table 2
enter image description here
table 3
enter image description here
I want to do with DAX this table joining in this SQL query
enter image description here
I want to create a table with the joining bloc
Can you help me ?
Kind Regards ;
I try to do it on power query but i have some speed issue
In power bi, you would address this by creating relationships in the model:
https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-create-and-manage-relationships
Please note that all joins are equivalent to outer joins in SQL. Some of what is in your ssample query is not valid SQL syntax - you can't have duplicate table names, "join" is repeated. However, if you wish to filter a table like T3.U2 = 'NW', you can simply add that as a WHERE clause in the query to import the data into the model or filter out the rows you want with PowerQuery (using the edit queries dialogue in power bi).
I am getting a different result in CR. I got the right result when I tried to run the query in SQL Server
here is the example of my situation
TB1
TB2
what I am trying to achieve is like this
BUT the CR's result is like this
here is my query:
SELECT * FROM TB1 tb1 LEFT JOIN TB2 tb2 WHERE tb1.ControlNo='IDU 2005.0001' AND tb2.Type = 'Applicant'
This can't be the SQL statement used in the Crystal report.
Are you using a Command as the data source in the report? If so, please show the command in your question.
If you are not using a Command, please show the table joins and the record selection formula.
Most likely, you are not using a Command and the record selection formula in the report design is simply wrong.
In my viz I have 2 tables, Orders and Returns
I have created a column called Order Id using Custom Split for Returns Table.
Now I'm trying to join the Orders and returns table using the Order Id but Order Id doesn't show up in the join drop down. how do i go about from here to create a custom join calculation option.
Image attachment :
When you split a column, it shows up as a "Calculated field". If you want to join on something which is not in the primary data source then you might as well create it first and then load the data in Tableau.
You must have noticed though that the split columns show up when you move to a worksheet. In your case, you can simply join on the "Order ID" which is present in both data sets (Superstore data).
Hope this helps.
I have a report where I need to join two tables but the fields are defined differently between them and I cannot change the table schemas because its JDEdwards. So I have one field as 30 characters left aligned and another another as 12 characters right aligned. The values will always be under 12 characters. So the issue is not the difference in size but the alignment/padding. I have to do a left join though. Right now the report is just comparing in the data selection and causing an inner join. But I need to change it to left join to stop losing rows. Is there any way to do it?
What happens is when I create the link to do the left join in Database Expert, I end up getting the data from the joined table all blank due to it not finding any rows because of the padding difference.
Since you only need one value from the table to be joined you can instead create a single SQL Expression to get the value for you without the need to add any tables to the report itself via Database Expert. You'll be able to use any valid SQL so you can do pretty much whatever you want without being constrained by Crystal.
For example, say your report consists of Table_A with a foreign key that is 30-characters left-aligned and you're trying to join to Table_B to get at some field, but that key is 12 characters right-aligned. A simple example in Oracle would be something like this:
case when "Table_A"."ForeignKey" is null then null
else
(select Table_B.SomeFieldYouWant
from Table_B
where rpad(Table_B.PrimaryKey,30,'0')="Table_A"."ForeignKey"
end
It's important to note that in a SQL Expression, any fields referenced with double quotes means that it's referring back to tables/fields in your report instead of new tables in the subquery; this is how you relate the subquery back to your report's data.
Is there a way to do ranking functions in Crystal Reports running against a SQL 2000 server?
http://msdn.microsoft.com/en-us/library/ms189798.aspx
I need to return the row number on table A before joining it to table B in Crystal Reports.
Thanks.
You can embed 'raw' SQL in a SQL Expression field. It must be a scalar value, however. See Crystal Reports: Using SQL Expression Fields.
You can do a running totals-style or row count formula on the data in the report itself. If you need to differentiate between table A and B's data then you can insert a constant into the select statements (do you mean join or union?) and then key on that field in your formula.