Solved

Joining 3 tables help

Posted on 2007-11-16
6
196 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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:xDJR1875
xDJR1875 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace &lt; with < 14 55
SQL Exceptions 3 37
MS SQL Inner Join - Multiple Join Parameters 2 18
Access 2010 Query Syntax 5 21
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

25 Experts available now in Live!

Get 1:1 Help Now