Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15722

VS 2019 VB.NET SQL statement to amalgamate four columns from joining two tables into two.

$
0
0
The plan is to take user input from a DGV1 cell, and show matches from two tables in DGV2 which has two columns: Description and Price, sorted Ascending by Description. When the user clicks an entry in DGV2, it inserts the description cell from DGV2 into the user's editing cell in DGV1. This is an Autocomplete system for entering descriptions in an invoice line entry.

I have two tables in Access which have the following fields (amongst others):
LineEntry: Description, Price
Stock: PartNo, Price.

If I just query either of the two tables (user chooses one table or the other), everything works. The challenge is to show Description and PartNo from the query in the DGV2 Description column, and Price from both tables in the DGV2 Price column, sorted on Description. Simples!

My query currently is:
Code:

pSQL = "SELECT DISTINCT [LineEntry.Description], [LineEntry.Price], [Stock.PartNo], [Stock.Price] FROM LineEntry, Stock WHERE [LineEntry.Description] LIKE '" & mCellContent & " OR [Stock.PartNo] LIKE '" & mCellContent & "' ORDER BY [Price]"
So the two questions are:
1. How to amalgamate the four fields into two, and then
2. how to sort by description on the result.
I'm wondering whether I have to do two individual queries then process the the results in an array, then fill DGV2. A single SQL query would be so much more elegant, though.

I haven't been able to find an example of this kind of thing anywhere, so any help would be appreciated.

Viewing all articles
Browse latest Browse all 15722

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>