My SQL runs fine but I am not sure whether my SQL code is efficient.
SELECT Customer_ID, Customer_Name, (SELECT PriceList_ID FROM qCustomerInfoPlan WHERE qCustomerInfoPlan.Customer_ID = 'A1002' AND qCustomerInfoPlan.ProductCategory_ID = 'BAT') AS Battery, (SELECT PriceList_ID FROM qCustomerInfoPlan WHERE qCustomerInfoPlan.Customer_ID = 'A1002' AND qCustomerInfoPlan.ProductCategory_ID = 'LUB') AS Lubricant, (SELECT PriceList_ID FROM qCustomerInfoPlan WHERE qCustomerInfoPlan.Customer_ID = 'A1002' AND qCustomerInfoPlan.ProductCategory_ID = 'FIL') AS Filter FROM qCustomerInfoPlan
Note
I am using Access (mdb) as my backend VB.Net Database.
qCustomerInfoPlan is a query from multipe tables from mdb.
Note that, 'A1002' would be replaced with '" textbox.Text "', where it would get from Form1. at my VB.Net code.
Reason for the code
The SQL's results are used at Popup Form2, where it displayed Customer Information such as Name, allocated Price for each Product Category. I created the code so its result is single row and easily allow me to bind the table from DataAdapter to my textboxes.
An example of the Binding code.
txtPlanBat.Text = FixNull(ds.Tables("CustomerInfoPlan").Rows(0).Item(2))
Question
As mentioned earlier, the SQL code works but I felt there could be a shorter version as the WHERE statements are repeated at every Custom Fields.
Thanks you all in advance.

New Topic/Question
Reply




MultiQuote





|