Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Joining 3 tables help

Posted on 2007-11-16
6
198 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:Daniel Reynolds
ID: 20300592
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
ID: 20300639
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
ID: 20300747
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 27

Accepted Solution

by:
MikeToole earned 125 total points
ID: 20300866
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:Daniel Reynolds
Daniel Reynolds earned 125 total points
ID: 20300902
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
ID: 31409603
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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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