?
Solved

Joining 3 tables help

Posted on 2007-11-16
6
Medium Priority
?
202 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 27

Accepted Solution

by:
MikeToole earned 500 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 500 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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