Solved

Joining 3 tables help

Posted on 2007-11-16
6
195 Views
Last Modified: 2010-04-21
I am going to post my sql query below. But let me explain that It works except for the "Company" results. For "Company" it doesn't recognize "Paid= 'true'", Because on the second query "select case = Paid Invoices" it returns Company invoices which are not paid. But it does fine with Client invoices. Does that makes sense? I will post the code and you tell me what you think: (this sqldatasource is populating a gridview.

Select Case ddlInvoices.SelectedItem.Text
            Case "Open Invoices"
                SqlDataSource1.SelectCommand = "SELECT * FROM Billing Left Outer Join Client ON Billing.ClientID = Client.ClientID) and (BillClient = 'True')) Left Outer Join Company ON ((Billing.ClientID = Company.CompanyID) and (BillClient = 'False')) WHERE ((Paid = 'false') and (ClientFirmName LIKE '%" & Textbox1.Text & "%' OR ClientShortName LIKE '%" & Textbox1.Text & "%') Or (CompanyName LIKE '%" & Textbox1.Text & "%'))"
            Case "Paid Invoices"
                SqlDataSource1.SelectCommand = "SELECT * FROM Billing Left Outer Join Client ON ((Billing.ClientID = Client.ClientID) and (BillClient = 'True')) Left Outer Join Company ON ((Billing.ClientID = Company.CompanyID) and (BillClient = 'False')) WHERE ((Paid = 'true') and (ClientFirmName LIKE '%" & Textbox1.Text & "%' OR ClientShortName LIKE '%" & Textbox1.Text & "%') Or (CompanyName LIKE '%" & Textbox1.Text & "%'))"
            Case "All Invoices"
                SqlDataSource1.SelectCommand = "SELECT * FROM Billing Left Outer Join Client ON ((Billing.ClientID = Client.ClientID) and (BillClient = 'True')) Left Outer Join Company ON ((Billing.ClientID = Company.CompanyID) and (BillClient = 'False')) WHERE ((ClientFirmName LIKE '%" & Textbox1.Text & "%' OR ClientShortName LIKE '%" & Textbox1.Text & "%') Or (CompanyName LIKE '%" & Textbox1.Text & "%'))"
        End Select
0
Comment
Question by:mlg101
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Expert Comment

by:xDJR1875
Comment Utility
What is the field type of the Paid field in Company?
What do some of the values look like when you query the table?
Is your database case sensitive? I see some times you check for "True" and sometimes "true" etc.
0
 
LVL 27

Expert Comment

by:MikeToole
Comment Utility
Chaeck that the field you're checking is really a text field with 'true' and 'false' values. (I prefer a bit or integer field with 0 and 1 to indicate true/false. Access uses an integer with values -1 and 0.
What is the back-end database server that you're using?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Paid is a bit field in MS SQL 2005. It is in the Billing table. I checked the database entries and they are all either True or False. I also changed the lowercase true to True, and it still didn't work. Any ideas?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Accepted Solution

by:
MikeToole earned 125 total points
Comment Utility
If Paid is a Bit field than you should code Paid = 1 in you where clause. comparing to a string should in reality generate an error.
0
 
LVL 17

Assisted Solution

by:xDJR1875
xDJR1875 earned 125 total points
Comment Utility
Mike is correct. The data designer may show it as true/false, but the underlying value for a bit field is 0 or 1 with 0 being false and 1 being true.
0
 
LVL 1

Author Closing Comment

by:mlg101
Comment Utility
you are both correct. I found the problem: when my database is updating, it wasn't changing the table from true to false, eventhough the checkbox was changing. I need to figure out why that is now. Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP.net pdf file opening in debug mode but not on web 13 23
Expando 4 33
String manipulation 15 48
sql calculate averages 18 21
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now