I have three table, Supplier, PO and PO Details.
I want to get the records when user pass the PO_Number then on that PO_Number whatever item code available, that item code and previous purchase item code should show.
below is the table structure.
CREATE TABLE [dbo].[Supplier](
[Supplier_No] [int] NOT NULL,
[SupplierName] [nvarchar](50) NULL,
CONSTRAINT [PK_Supplier] PRIMARY KEY CLUSTERED
(
[Supplier_No] 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
CREATE TABLE [dbo].[PO](
[Po_No] [int] IDENTITY(1,1) NOT NULL,
[PO_Number] [nvarchar](50) NULL,
[PO_Date] [date] NULL,
[SupplierNo] [int] NULL,
CONSTRAINT [PK_PO] PRIMARY KEY CLUSTERED
(
[Po_No] 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].[PO] WITH CHECK ADD CONSTRAINT [FK_PO_Supplier] FOREIGN KEY([SupplierNo])
REFERENCES [dbo].[Supplier] ([Supplier_No])
GO
ALTER TABLE [dbo].[PO] CHECK CONSTRAINT [FK_PO_Supplier]
GO
CREATE TABLE [dbo].[PODetails](
[PO_No] [int] NULL,
[ItemCode] [nvarchar](50) NULL,
[ItemDescription] [nvarchar](50) NULL,
[Qty] [decimal](18, 2) NULL,
[UnitPrice] [decimal](18, 2) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PODetails] WITH CHECK ADD CONSTRAINT [FK_PODetails_PO] FOREIGN KEY([PO_No])
REFERENCES [dbo].[PO] ([Po_No])
GO
ALTER TABLE [dbo].[PODetails] CHECK CONSTRAINT [FK_PODetails_PO]
GO
example user pass the PO Number = 123
then first get what are the item on that PO. example got three item
Item =A
Item = B
Item=C
then get previous all the purchase related to Item=A, Item=B and ItemC
Item | PO No | Supplier | Qty | Unit Price |
---|---|---|---|---|
ItemA | 123 | A | 1 | 12 |
ItemA | 22 | B | 2 | 13 |
ItemB | 123 | A | 1 | 66 |
ItemB | 34 | C | 1 | 17 |
ItemC | 123 | A | 1 | 2 |
ItemC | 345 | D | 1 | 4 |
Thanks & Regards,
Basit.