473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL help

I have four tables: tblOrders, tblSKUItems, tblVendorItems and tblVendors.


Here's my tblOrders table:
Expand|Select|Wrap|Line Numbers
  1. SKU ITEM #    VendorOrder
  2. 123
  3. 124
  4. 254
  5. 542
  6. 324
  7. 786
  8. 475
  9. 521
  10. 354
  11. 254
  12. 128
  13. 009
  14. 010
  15. 704
  16. 157
  17. 858
  18. 821
  19. 724
  20. 428
  21. 129
  22. 219
  23. 481
  24. 484
  25. 411
  26. 442
  27. 754
  28. 321
  29.  
This table exists to show the order I need to make to the vendor (VendorOrder) for each particular SKU item.

Right now the VendorOrder is blank, the point of this question is to fill it up, but I'll get to that later.



Here's the tblSKUItems table:

Expand|Select|Wrap|Line Numbers
  1. SKU ITEM # 
  2. 123
  3. 124
  4. 254
  5. 542
  6. 324
  7. 786
  8. 475
  9. 521
  10. 354
  11. 254
  12. 128
  13. 009
  14. 010
  15. 704
  16. 157
  17. 858
  18. 821
  19. 724
  20. 428
  21. 129
  22. 219
  23. 481
  24. 484
  25. 411
  26. 442
  27. 754
  28. 321
  29.  
The point of this table is to contain all the SKU item #s



This is what the tblVendors table looks like:

Expand|Select|Wrap|Line Numbers
  1. Vendors
  2. BAREWA
  3. CCCNTL
  4. HDSPLY
  5. KISSLR
  6.  
This table is to show all the vendors.



And lastly there's the tblVendorItems:

Expand|Select|Wrap|Line Numbers
  1. ID   SKU   Vend  Pri  VItem   SameDay 
  2. 1    123   MDTV   2   4987    Yes     
  3. 2    123   RYUU   1   464     Yes     
  4. 3    124   MDTV   2   5001    Yes     
  5. 4    124   RYUU   1   463     Yes     
  6. 5    254   MDTV   2   3998    Yes     
  7. 6    254   RYUU   1   085     Yes     
  8. 7    542   MDTV   2   5000    Yes     
  9. 8    542   RYUU   1   357     Yes     
  10. 9    324   MDTV   2   4304    Yes     
  11. 10   324   RYUU   1   874     Yes     
  12. 11   786   MDTV   2   4387    Yes     
  13. 12   786   RYUU   1   919     Yes     
  14. 13   475   MDTV   2   7653    Yes     
  15. 14   475   RYUU   1   898     Yes     
  16. 15   521   MDTV   2   4389    Yes     
  17. 16   521   RYUU   1   078     Yes     
  18. 17   354   MDTV   2   4020    Yes     
  19. 18   354   RYUU   1   489     Yes     
  20. 19   254   MDTV   2   4300    Yes     
  21. 20   254   RYUU   1   167     Yes     
  22. 21   128   MDTV   2   4760    Yes     
  23. 22   128   RYUU   1   168     Yes     
  24. 23   009   MDTV   2   7542    Yes     
  25. 24   009   RYUU   1   597     No      
  26. 25   010   MDTV   2   9677    Yes     
  27. 26   010   RYUU   1   598     Yes     
  28. 27   704   MDTV   0   4555    Yes     
  29. 28   704   LOWE   2   23-OH   No      
  30. 29   704   RYUU   3   101     Yes     
  31. 30   704   GVHH   1   804521  Yes     
  32. 31   157   MDTV   0   1700    Yes     
  33. 32   157   RYUU   1   416     Yes     
  34. 33   157   GVHH   2   830921  Yes     
  35. 34   858   MDTV   0   4044    Yes     
  36. 35   858   LOWE   0   23-HF   Yes     
  37. 36   858   RYUU   1   413     Yes     
  38. 37   858   GVHH   2   207871  Yes     
  39. 38   821   MDTV   0   4817    Yes     
  40. 39   821   LOWE   0   23-HJ   Yes     
  41. 40   821   RYUU   1   132     Yes     
  42. 41   821   GVHH   2   507702  Yes     
  43. 42   724   MDTV   0   8978    Yes     
  44. 43   724   LOWE   0   23-IU   Yes     
  45. 44   724   RYUU   1   533     Yes     
  46. 45   724   GVHH   2   434501  Yes     
  47. 46   428   MDTV   0   4567    Yes     
  48. 47   428   LOWE   3   23-YU   Yes     
  49. 48   428   RYUU   1   471     No      
  50. 49   428   GVHH   2   459601  Yes     
  51. 50   129   MDTV   0   5287    Yes     
  52. 51   129   LOWE   0   23-FF   Yes     
  53. 52   129   RYUU   1   503     Yes     
  54. 53   129   GVHH   2   784701  Yes     
  55. 54   219   MDTV   0   5647    Yes     
  56. 55   219   LOWE   0   42-SD   Yes     
  57. 56   219   RYUU   1   219     Yes     
  58. 57   481   MDTV   0   4456    Yes     
  59. 58   481   LOWE   0   42-BG   Yes     
  60. 59   481   RYUU   1   925     Yes     
  61. 60   484   MDTV   0   6547    Yes     
  62. 61   484   LOWE   0   42-BB   Yes     
  63. 62   484   RYUU   1   914     Yes     
  64. 63   411   MDTV   0   6457    Yes     
  65. 64   411   LOWE   0   46-EH   Yes     
  66. 65   411   RYUU   1   470     Yes     
  67. 66   442   MDTV   0   4564    Yes     
  68. 67   442   LOWE   0   31-TF   Yes     
  69. 68   442   RYUU   1   488     Yes     
  70. 69   754   MDTV   0   4898    Yes     
  71. 70   754   LOWE   0   31-AS   Yes     
  72. 71   754   RYUU   1   987     Yes     
  73. 72   321   MDTV   0   4567    Yes     
  74. 73   321   LOWE   0   31-MN   Yes     
  75. 74   321   RYUU   1   949     Yes  
  76.  
Vend = Vendor

Pri = VendorPriority

VItem = VendorItem

SameDay = CanShipSameDay


This table exists to show all the vendors item #s and how they correlate to each sku item #.

This table also shows the priority for each vendor item. The lower the number, the higher the priority (besides 0). If it does say 0, it means that vendor doesn't have that item.

So if I need to buy SKU Item # 123, I would choose RYUU who's vendor item # is 464 because their priority number is 1 while MDTV's priority is 2.

But there's another factor involved as well, CanShipSameDay. This needs to say "Yes" or else we can't make the order. (CanShipSameDay's datatype is Yes/No)

So if I wanted to order SKU item # 009, I'd choose MDTV because, although they have a higher priority number than RYUU, RYUU's CanShipSameDay says "No" while MDTV says "Yes".




So my problem is I'm trying to create SQL code to automatically add VendorOrder values based on ttblVendorItems.

This query needs to check each SKU item in tblVendorItems and make sure the CanShipSameDay is "Yes", then choose the vendor with the lowest priority, not 0, for that SKU item.

After the query finds the vendor with that fits the description above, the query will add, in the table tblOrders under the field VendorOrder, the name of the vendor.

How do I do this?
Jul 1 '14 #1
3 1068
Seth Schrock
2,965 Expert 2GB
I would use a subquery to get the vendor information that you are looking for. Something like the following.
Expand|Select|Wrap|Line Numbers
  1. SELECT SKU
  2. , [Item #]
  3. , Vend
  4. FROM tblOrders As O INNER JOIN (SELECT TOP 1 Vend, SKU 
  5.    FROM tblVendorItems
  6.    WHERE SameDay = 'Yes'
  7.       AND tblVendorItems.SKU = O.SKU
  8.    ORDER BY Pri) As VI ON O.SKU = VI.SKU
I don't have a system in place where I can test this, so there might be some errors in the aliases, but it should get you on the right track.
Jul 1 '14 #2
Rabbit
12,516 Expert Mod 8TB
This table also shows the priority for each vendor item. The lower the number, the higher the priority (besides 0). If it does say 0, it means that vendor doesn't have that item.
If the vendor doesn't have the item, it shouldn't be in the table. If they don't have the item, how does it even have a vendor specific item number?

What is tableOrders supposed to be?

If it's supposed to be a listing of orders placed or to be placed, it shouldn't be prepopulated with items. It should also have a unique order number. And probably an order date.

If it's supposed to be a listing of who to buy from and not necessarily of actual orders, then you don't need a table for that. You can do it with a min aggregate query on the Vendor Item table.
Jul 1 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Jrod,

Please see one of my previous posts on one of your previous questions.

I am in absolute agreement with Rabbit. You should not pre-populate tblOrders (in fact, you should not have that Table at all). You should find out who to buy from at run-time, as your vendors an availability may change. Otherwise, you must constantly be updating redundant data in your db, which is not recommended.
Jul 2 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
3
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.