Solved

Joining 3 tables help

Posted on 2007-11-16
6
199 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
[X]
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
  • 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
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.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reactjs with .NET 3 70
SQL Query Syntax error after > 11 39
vb.net datagrid scroll automatically to the first found row 11 28
UPDATE JOIN multiple tables 5 19
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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