I'm trying to put a report together using Crystal Reports. I have to display a list of "class numbers" and the description of those classes. If there are prerequisites for those classes, I need to list those (the class number) as well as a description/title.
Currently I am able to display everything but the prerequisite descriptions. I believe I have to preform a self join since I'm only using one table. What I've done so far is use the command option when entering the tables I want to use for the report. In that command I have
SELECT Main.prerequisite, Sub.course_no, Sub.description
FROM course Main
JOIN course Sub ON Main.prerequisite = Sub.course_no
where main.prerequisite is not null
The table is called "course" while the columns are "course_no", "description", "prerequisite".
Anytime I add "description" to the report, it only gives me the course_no's corresponding description, not the prerequisite description.
I'm not sure what I'm doing wrong or what I'm not doing at all, but any help would be greatly appreciated. Thank you.
I figured a work around and thought I should post it here. Hopefully to avoid wasting anyone's time as well as providing my solution to anyone that may have a similar issue.
I simply created a view in SQL
Create view preReqs AS
SELECT Main.course_no AS [course_no]
,Main.description AS [description]
,Main.prerequisite AS [prerequisite]
,Sub.description AS [preReqDescription]
FROM course As Main
LEFT OUTER JOIN course As Sub ON Main.prerequisite = Sub.course_no
After I created that, I just imported the view instead of the table itself into the Crystal Report. I was then able to group by whatever I wished.
Hopefully this will help anyone else that may run into this issue. Thank you for everyone that provided their time/input as well. I appreciate it.
Related
Hi & thanks for reading/helping!
I have a simple table with email addresses and domain names. In an equally simple form I can list in a listbox the email addresses that go with each domain name using:
SELECT Emails.EmailAddr FROM Emails WHERE Emails.[DomainName]=Form![DomainName];
and it works perfectly. However despite trying every permutation going I CANNOT make the same thing work in a report :-( even if I try saving the form as a report. Can anybody help me understand why this doesn't work ...
SELECT Emails.EmailAddr FROM Emails WHERE Emails.[DomainName]=Report![DomainName];
If I omit the "Report!" then I get a list of all email addresses but with every other reference I get nothing at all or an error.
My forehead is bruised from banging it on the table!
Jimmy
The syntax for referring to report controls is the following:
Reports!ReportName!ControlName
You should be able to use that in your SQL clause.
I'm sorry if my question sounds confusing.I just started learning web2py recently,in this exercise I'm trying to make a simple users management webpage with the admin can assign the users theirs work lists,note and deadline
db.define_table('auth_manager',Field('name','string',requires=IS_NOT_EMPTY()))
db.define_table('manager',Field('user','string','reference user.name'),
Field('workname','text',requires=IS_NOT_EMPTY()),
Field('deadline','date'),)
db.manager.deadline.requires=IS_DATE_IN_RANGE(format=T('%Y-%m-%d'),
minimum=now,maximum=now+datetime.timedelta(60))
I thought of adding the manager's username in auth_manager table using appadmin's new record function.This is my user table
db.define_table('user',Field('name','string',requires=IS_NOT_EMPTY()),
Field('password','password'),
Field('workname','text'),
Field('deadline','date'),
format='%(name)s')
I wanted to insert workname and deadline into user table right after I add those form on manager but I couldn't find any other methods except the update or update_or_insert functions but both don't work because those fields can't be empty and their ids aren't the same value and multiple references to a single table don't work .
One last question,I want to use web2py's RBAC but the first & last name fields are often unnecessary if I want to use a full name field is there other way to do it?
Sorry for the long post,I hope I made my question clear.
You can use the tables from auth and let web2py to handle everything in between.
The following code should resolve your problem:
db.define_table('manager', 'reference auth_user'),
Field('workname', 'text', requires=IS_NOT_EMPTY()),
Field('deadline', 'date'))
I make a query (with \yii\db\ActiveQuery) with joins, and some fields in "where" clause become ambigous. Is there a nice and short way to specify the name of the current model`s (ActiveRecord) table (from which one the ActiveQuery was instantiated) before the column name? So I can use this all the time in all cases and to make it short.
Don't like doing smth like this all the time (especially in places where there're no joins, but just to be able to use those methods with joins if it will be needed):
// in the ActiveQuery method initialized from the model with tableName "company"
$this->andWhere(['{{%company}}.`company_id`' => $id]);
To make the "named scopes" to work for some cases with joins..
Also, what does the [[..]] mean in this case, like:
$this->andWhere(['[[company_id]]' => $id]);
Doesn't seem to work like to solve the problem described above.
Thx in advance!
P.S. sorry, don't have enough reputation to create tag yii2-active-query
to get real table name :
Class :
ModelName::getTableSchema()->fullName
Object :
$model::getTableSchema()->fullName
Your problem is a very common one and happens most often with fields liek description, notes and the like.
Solution
Instead of
$this->andWhere(['description'=>$desc]);
you simply write
$this->andWhere(['mytable.description'=>$desc]);
Done! Simply add the table name in front of the field. Both the table name and the field name will be automatically quoted when the raw SQL is created.
Pitfall
The above example solves your problem within query classes. One I struggled over and took me quite some time to solve was a models relations! If you join in other tables during your queries (more than just one) you could also run into this problem because your relation-methods within the model are not qualified.
Example: If you have three tables: student, class, and teacher. Student and teacher probably are in relation with class and both have a FK-field class_id. Now if you go from student via class to teacher ($student->class->teacher). You also get the ambigous-error. The problem here is that you should also qualify your relation definitions within the models!
public function getTeacher()
{
return $this->hasOne(Teacher::className(), ['teacher.id' => 'class.teacher_id']);
}
Proposal
When developing your models and query-classes always fully qualify the fields. You will never ever run into this problem again...that was my experience at least! I actually created my own model-gii-template. So this gets solved automatically now ;)
Hope it helped!
Ok, I've spent the day getting my models, stores and views all setup.
I have the ajax and grouping working fine for my ListView.
My question is, I want to order & group by 'day' and inside of that grouping, I want to group by 'order_id'.
Can this be done? Would it be a new view inside the list's cell?
I'm new to Sencha and have searched all through their docs/google/etc.
Thanks for any insight.
Take a look at the grouper config on Ext.data.Store. You may have to be a bit creative with the logic, but you should be able to accomplish it.
In the end I didn't need a list within a list.
I ended up resolving this by changing the JSON format it was receiving and then using Ext.XTemplate(); looping through using <tpl for="items">.
Thanks for the comments anyways.
Hey there I am trying to learn SQL by trying to complete online questions and I'm trying to create a view.
I have created a SELECT query that works and now trying to turn it into a view, though when following the online instructions and enter the script that should create a view I come up with the duplicate field error.
I've looked into it and it may be "doctor.fullname" as a duplicate field but this is from another table. Andway I have deleted and still tried it but the error still appears.
I know there is probably an easy solution and sorry to bother you with this but it will be must appreciated.
CREATE VIEW patient_registration_form
AS
SELECT
patient.patient_id,
patient.nok_no,
patient.f_name,
patient.s_name,
patient.sex,
patient.dob,
patient.marital_status,
patient.date_registered,
nok.tel_no,
nok.full_name,
nok.address,
nok.relationship,
doctor.doctor_id,
doctor.clinic_no,
doctor.full_name,
doctor.address
FROM doctor, patient, nok
WHERE doctor.doctor_id = patient.doctor_id
AND nok.nok_no = patient.nok_no;
You're returning several columns with the same name... full_name and address... even though they're from different tables. In this case, you have to give them different aliases:
SELECT
patient.patient_id,
patient.nok_no,
patient.f_name,
patient.s_name,
patient.sex,
patient.dob,
patient.marital_status,
patient.date_registered,
nok.tel_no,
nok.full_name as nok_full_name,
nok.address as nok_address,
nok.relationship,
doctor.doctor_id,
doctor.clinic_no,
doctor.full_name as doctor_full_name,
doctor.address as doctor_address
You have two full_name listed... one for nok.full_name and one for doctor.full_name. One needs to be renamed such as nok.full_name as nok_full_name.