Hello all, I am new to the forum and new to TSql so please be gentle.
I am trying to create my first procedure to show a set of results from a couple of other tables.
I have made a start but struggling to get it to work. As I say I am new so it will probably be something so basic I am missing but would appreciate so help and guidance towards my results.
So here is what I want the end table to look like:
t1.Branch, (data held on all tables to identify which branch)
t1.[route], (data held on table 1 only, is unique by cust_code and del_order_no)
t1.[drop_number], (data held on table 1 only, is unique by cust_code and del_order_no)
t1.[cust_code], (data held on table 1 to link to the route and drop_number, may be more than one cust_code with different del_order_no but the same route and drop_number)
t2.[business_name], (data held on table 2 only)
t2.[mob_no], (data held on table 2 only)
t2.[post_code], (data held on table 2 only)
t2.[addr_1], (data held on table 2 only)
NULL AS 'Payment Method', (blank column)
NULL AS 'ETA', (blank column)
NULL AS 'Weight', (blank column)
NULL AS 'Cages', (blank column)
NULL AS 'Pallets', (blank column)
NULL AS 'Bread', (blank column)
NULL AS 'Stamps', (blank column)
NULL AS 'Credit', (blank column)
NULL AS 'Cigarettes', (blank column)
So as you can see, I only have two tables (t1 and t2) that all my data is stored.
I basically want to be able to enter a date (orderdue, held on T1, and i want to set this as a variable) and branch and then be given all the results ordered by route, drop_number asc.
My issue is that there may be multiple rows and results with the same cust_code, orderdue but always a different del_order_no e.g..
cust del_order_no route drop orderdue
a 001 1 1 27-05-2022
a 002 1 1 27-05-2022
a 003 1 1 27-05-2022
b 004 1 2 27-05-2022
c 005 1 3 27-05-2022
d 006 2 1 27-05-2022
e 007 2 2 27-05-2022
e 008 2 2 27-05-2022
so as you can see a customer may have more than one order, all with a different del_order_no but with the same orderdue date but the route and drop_number will be the same. So in my results I just want it all merged together so i just get...
cust route drop
a 1 1
b 1 2
c 1 3
d 2 1
e 2 2
My final issue is that T1 will have details for customers who I don't want to know about, so I need to look at T2 before doing any work and only find customers with a field called route set to = xxxx and then bring my results for those customers with details on T1 only.
I hope this make some sense.
and thanks in advance
Richard