Everyone was so helpful it was great last time, however again I am needing insight into this issue, and frankly I don't really know where to begin.
The two main tables I am dealing with are ShtStock:
GO
/****** Object: Table [dbo].[ShtStock] Script Date: 30/01/2020 8:42:44 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ShtStock](
[ShtStockId] [int] IDENTITY(1,1) NOT NULL,
[Barcode] [nvarchar](500) NULL,
[PartNumber] [nvarchar](50) NOT NULL,
[Description] [nvarchar](500) NOT NULL,
CONSTRAINT [PK__ShtS__1B17B9B1711A71B9] PRIMARY KEY CLUSTERED
(
[ShtStockId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
And then StockDelivered
GO
/****** Object: Table [dbo].[StockDelivered] Script Date: 30/01/2020 8:47:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StockDelivered](
[DeliveredId] [int] IDENTITY(1,1) NOT NULL,
[DeliveryDate] [datetime] NOT NULL,
[Barcode] [nvarchar](500) NULL,
[ShtStockId] [int] NOT NULL,
[Quantity] [float] NOT NULL,
[WaterBodyID] [int] NOT NULL,
[RegistrantEmail] [varchar](50) NOT NULL,
PRIMARY KEY CLUSTERED
(
[DeliveredId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[StockDelivered] WITH CHECK ADD CONSTRAINT [FK_StockDelivered_ShtStock] FOREIGN KEY([ShtStockId])
REFERENCES [dbo].[ShtStock] ([ShtStockId])
GO
ALTER TABLE [dbo].[StockDelivered] CHECK CONSTRAINT [FK_StockDelivered_ShtStock]
GO
This all works fine...as long as there is an entry in the ShtStock to match the StockDelivered. No issues so far, this is for information.
I am upsizing from an MS Access application and very new to SQL, so please if I am asking dumb questions please understand its because it is all very foreign to me still.
The actual issue I have is there are barcodes in the system that are not official company stock items. Best way to explain this is real world, and I will use laundry powder as most people know what that is...I hope.
I purchase the laundry powder in 25 kilogram sacks. The 25 kilogram sack has a ShtStock. PartNumber call it 1234 and a ShtStockID of 23.
I then sell the 25 kilograms in 1 kilogram lots which I have created a special part number for. Call it SPC133 with a ShtStockID 189.
In MS Access my solution is to create a bridge table, and this may work in SQL, haven't got this done yet, but need it to make the story clearer for the part I am not sure how to approach.
Bridge table contains:
ShtStockID (189 in our example)
Divisor (25 in the case of the laundry powder example)
RelatedStockID (23 in our example)
This is simple enough.
In MS Access what I then do is I run a bit of VBA to tell it if there is a ShtStockID in teh Bridging Table, then divide the StockDelivered.Quantity by the Bridge Table.Divisor and substitute this amount with the RelatedStockID and associated description into the query.
I am unclear how to go about approaching this, or even what to ask about or search for to learn how to do this. I apologise if this doesn't make sense, please ask questions as need to clarify.