scubafrog79
Programmer
I am trying to create an update statement that will update a column.
Here is the scenario. Let's say I have a bunch of products and I need to tag any of those products that exist in two different locations. Note the product can be in the same location more than once at times, I don't want to tag that product as being in a different location, since it's not.
Results would look like
Product MultiLoc
1234 Y
2345 N
4567 N
5678 Y
Hope the following scripts are helpful.
Here is the scenario. Let's say I have a bunch of products and I need to tag any of those products that exist in two different locations. Note the product can be in the same location more than once at times, I don't want to tag that product as being in a different location, since it's not.
Results would look like
Product MultiLoc
1234 Y
2345 N
4567 N
5678 Y
Hope the following scripts are helpful.
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Products](
[ProdID] [int] IDENTITY(1,1) NOT NULL,
[MultiLoc] [int] NULL,
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED
(
[ProdID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [Products] ON
insert into Products
(ProdID)
values
(1234)
, (2345)
, (4567)
, (5678)
SET IDENTITY_INSERT [Products] OFF
SQL:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProductLocation](
[PK] [int] IDENTITY(1,1) NOT NULL,
[ProdID] [int] NULL,
[LocationID] [int] NULL,
CONSTRAINT [PK_ProductLocation] PRIMARY KEY CLUSTERED
(
[PK] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
insert into [ProductLocation]
(ProdID, LocationID)
values
(1234,22)
,(1234,33)
,(1234,22)
,(2345,33)
,(2345,33)
,(2345,33)
,(4567,79)
,(5678,55)
,(5678,33)
,(5678,55)