I've created crystal reports using ADO.NET datasets, the reports are working just fine but now my question is:.
How do I make my report to get data from multiple tables because I tried using INNER JOIN method and it didn't work,it displayed nothing....
So can someone give me an idea on how to make crystal report to get data from multiple tables using VB.NET? And tell me the purpose of "SQL Expression" in Crystal Reports.
Please, Thank You.
Con.close
Con.open
Query = "select customers.cust_id,customers.cust_fname,customers.cust_lname,invoices.inv_id,invoices.inv_date from customers Inner Join Invoices ON customers.cust_id = invoices.cust_id where customers.cust_id = '"& txtcustnr.text & "'"
Con.close
Read this to get you started on the purpose of SQL Expression Fields. And without any code for your table joins nobody will be able to help you out.
EDIT:
Instead of where customers.cust_id = '"& txtcustnr.text & "'" try where customers.cust_id = txtcustnr.text
I don't know what data is in "txtcustnr.text", but if you you want the data from txtcustnr.text to be the same as customers.cust_id, then try the above WHERE clause.
Related
I am having an issue with a date literal not returning any results when I run an SOQL query. The query is as follows:
Select * From dbo.Case WHERE CreatedDate = YESTERDAY
With the query, I would like to obtain case data from the previous day. I know there is data available that was created the previous day. The results of the query when I preview it, though, are an empty set with no error message.
A different wrinkle that makes this not quite a strict SOQL issue is that I am trying to use this query as an SQL command on an ADO.NET connection using the CData ADO.NET driver to connect to a SalesForce.com instance. My goal is to be able to build SSDT packages that will allow me to stage the data from SalesForce into our SQL Server for processing there.
I have similar issues using the LAST_N_DAYS date literal as well.
I believe I should be using SOQL to query in the SQL command text field for the ADO.NET source connection but I am not 100% sure about that. I know for certain that I cannot use T-SQL because it does not recognize the GETDATE().
Any guidance on how to pull the records from Case for the previous day or where the query I am using might be wrong would be greatly appreciated.
Found an answer. The following SQL command will pull the data from the previous day:
Select * From dbo.Case Where CreatedDate = 'YESTERDAY'
The single quotes evaluate the yesterday date literal as expected.
Likewise, the following SQL statement will get the last 30 days of data.
Select * From dbo.Case Where CreatedDate = 'LAST_N_DAYS:30'
Thanks to anyone who researched and attempted the question! :)
Using SQL 2008R2
I have a need to create a SSRS report where the user can specify the Columns returned AND the order in which they are returned. Dynamic data and ordering.
Example:
Available Columns A,B,C,D,E
User specifies they want to see: C,D,A
No issue on the data side, I'm using a stored procedure and can handle this no issue.
On the SSR side, I've seen similar question mention using a "matrix".
However I'm looking for opinions on the best approach on how to handle this on the SSRS Side. What is the best way to handle dynamic number of returned columns and dynamic ordering of columns..
As has already been mentioned, SSRS is not the way to go for this.
If the order of the columns were not customizable then you could handle column visibility using SSRS expressions but presenting the columns in a dynamic order is not easy in SSRS.
For that kind of thing you could use Excel's pivot table functionality, use a 3rd party .NET solution like MVC or build some home-grown ASP.net solution.
Try this:
1. In SSRS, create parameters ColumnA and ColumnB
Create your dataset---don't directly type your query, use expression (the fx button)
In the expression, you can write your query like this:
="SELECT " + Parameters!ColumnA.Value + "," + Parameters!ColumnA.Value + " FROM Table"
You can solve your dynamic ORDER BY problem by the same way.
I have an ADO query that I use to gather data and later use to update that data. (Embarcadaro C++ Xe2 & Oracle 10g). Rownum (aliased to pgnum) is also selected and in this query. When posting data edited via this query, I receive invalid identifier "pgnum". This seems to be an issue specifically with ADO as this same code worked in previous versions of our software. We recently converted all our queries to ADO from Tquery (old BDE Driven). Adding "pgnum" to the queries persistent fields does not help. Any advice would be greatly appreciated.
Table1 is an ADOQuery.
sql = "SELECT ROWNUM PGNUM, A.* FROM DOCUMENT_IMAGE A WHERE DOCNO = " + String(Form1->qryDocumentDOCNO->AsInteger) + " ORDER BY ROWNUM ";
Table1->Close();
Table1->SQL->Clear();
Table1->SQL->Add(sql);
Table1->Open();
Table1->Edit();
Table1IMAGE->LoadFromFile(filepath);
if (Table1->Modified){
Table1->Post();
}
After tons of research and testing I could get nothing to work while keeping rownum in the query. I'm honestly not sure what it was accomplishing, I took this project over from someone else. Anyway, I removed rownum and used a different field to order the query by, problem solved.
I have the following query, which executes perfectly in SSMS. However, when I paste the code into a newly created dataset and click "execute", BIDS crashes and closes without notice - any suggestion as to the reason?
Code:
SELECT MSP_EpmProject_UserView.ProjectOwnerName,
MSP_EpmProject_UserView.ProjectUID,
CurrentActivities.Activities_Current
FROM MSP_EpmProject_UserView
Left Join
(Select t1.projectUID, STUFF(
(Select ', ' + t2.TaskName
From (SELECT MSP_EpmProject_UserView.ProjectUID, MSP_EpmTask_UserView.TaskName
FROM MSP_EpmAssignmentByDay_UserView INNER JOIN MSP_EpmTask_UserView ON MSP_EpmAssignmentByDay_UserView.TaskUID = MSP_EpmTask_UserView.TaskUID INNER JOIN MSP_EpmProject_UserView on MSP_EpmAssignmentByDay_UserView.ProjectUID = MSP_EpmProject_UserView.ProjectUID
WHERE (MSP_EpmAssignmentByDay_UserView.TimeByDay = #refDate) AND MSP_EpmProject_UserView.[Project Departments] = #prjDep) t2
Where t1.ProjectUID = t2.ProjectUID
Order by t2.TaskName
For XML Path(''), Type).value('.','varchar(max)'),1,2,'') as Activities_Current
From
(SELECT MSP_EpmProject_UserView.ProjectUID, MSP_EpmTask_UserView.TaskName
FROM MSP_EpmAssignmentByDay_UserView INNER JOIN MSP_EpmTask_UserView ON MSP_EpmAssignmentByDay_UserView.TaskUID = MSP_EpmTask_UserView.TaskUID INNER JOIN MSP_EpmProject_UserView on MSP_EpmAssignmentByDay_UserView.ProjectUID = MSP_EpmProject_UserView.ProjectUID
WHERE (MSP_EpmAssignmentByDay_UserView.TimeByDay = #refDate) AND MSP_EpmProject_UserView.[Project Departments] = #prjDep) t1
Group by t1.ProjectUID) CurrentActivities On CurrentActivities.ProjectUID = MSP_EpmProject_UserView.ProjectUID
WHERE (MSP_EpmProject_UserView.[Project Departments] = #prjDep)
I would try to create a view and see if that still crashes. BIDS is not meant to be SSMS and it's interpretation of the XML parsing may be blowing it up. You are translating values from a query using 'for xml', with 'type' which gets rid of the root element of the xml, then extending it, then nesting it, then nesting that, then left joining that, then you have a regular sql expression. BIDS is not meant to do a lot of dynamic SQL, intense CLR, and xml node or xquery expressions nesting things in my experience. Everytime I have thrown lot's of XML, table variables, recursive CTE's, dyanmic SQL... it blows up. It's interpreter is blowing up I am guessing as it does not have the resources SSMS does to evaluate the expression and gives up in the form of a blow up.
My thought on doing the view is that the interpretation will be then forced on the SQL engine in the database to perform it's logic and execution plan and then return the results. BIDS will just know it is a call to perform but not have to reason out the logic. In my recollection SSRS with BIDS on 2008 has many issues with complex query logic and SSAS cubes.
This may not work but I know putting things to views, functions, or procs will often times fix issues with complex logic the engine has to perform.
I managed to work my way around this by just pasting the code into the dataset, updating the fields, NOT clicking the "query designer" and by manually adding the parameters BIDS did not detect automatically (in my case an INT parameter for DATEADD() ). When I then close the dataset windows and use the dataset in my report, everything works fine
I have a database that has two tables that need to be linked, but in one table the data is padded with zeros. For example, the tables may look like this:
CUSTOMER.CUSTNUM = 00000000123456
CUSTOMERPHONE.CUSTNUM = 123456
I can't figure out how to get these tables to properly join.
What I'm trying to do now is trick Crystal Reports into specifying the Join clause by adding the following to the selection expert:
Right ({CUSTOMER.CUSTNUM}) = {CUSTOMERPHONE.CUSTNUM}
That's not working though, and I get no records at all in my report.
Any ideas?
Crystal doesn't like heterogeneous joins.
Options:
use a command object, which will give you more control over the linkage
create a SQL Expression that performs the desired concatination; link fields in the record-selection formula
use a subreport for the linked table
alter the table to make the data types compatible
create a SQL view that performs the joins
First thing, why does CUSTOMER.CUSTNUM have leading zeros in the first place? It seems to me that it should be a NUMERIC data type instead of a VARCHAR. CUSTNUM should be consistent in all of the tables. Just a thought.
Anyway, to answer your question, you could try creating a SQL Command in Crystal to join the two tables. In the join, just use your database's function for converting from a varchar to a number. For example, in Access you could do:
SELECT *
FROM `Customer`
LEFT OUTER JOIN `Orders` ON `Orders`.`Numeric Customer ID` = CLng(`Customer`.`Varchar Customer ID`)
If fastest performance isn't an issue, you can accomplish this using Select Expert. I think the problem is your formula.
Try changing your formula from this:
{CUSTOMERPHONE.CUSTNUM} = Right({CUSTOMER.CUSTNUM})
to this:
{CUSTOMERPHONE.CUSTNUM} = Right({CUSTOMER.CUSTNUM}, Length({CUSTOMERPHONE.CUSTNUM}))