Is there a syntax for using IN () with multiple columns?
For instance:
What I want is quantities of Red Small, Blue XXL, and White XL. I can do this with a CTE like the following but is there an easier solution?
[pre]mColor mSize mQty
Blue XXL 10
Red S 8
White XL 0[/pre]
Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
For instance:
SQL:
CREATE TABLE [ColorSizeQuantity](
[Color] [nchar](10) NOT NULL,
[Size] [nchar](10) NOT NULL,
[Quantity] [int] NOT NULL
) ON [PRIMARY]
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Red ', N'L ', 10)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Red ', N'XL ', 5)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Red ', N'S ', 8)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Blue ', N'S ', 3)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Blue ', N'M ', 5)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'Blue ', N'XXL ', 10)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'White ', N'S ', 0)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'White ', N'XS ', 3)
GO
INSERT [ColorSizeQuantity] ([Color], [Size], [Quantity]) VALUES (N'White ', N'L ', 20)
GO
What I want is quantities of Red Small, Blue XXL, and White XL. I can do this with a CTE like the following but is there an easier solution?
SQL:
WITH
cteCombinations as
(SELECT 'Red' mColor, 'S' mSize
UNION SELECT 'Blue', 'XXL'
UNION SELECT 'White', 'XL'
)
SELECT mColor, mSize, IsNull(Quantity ,0) mQty
FROM ColorSizeQuantity
RIGHT JOIN cteCombinations ON mColor = Color AND mSize = Size
[pre]mColor mSize mQty
Blue XXL 10
Red S 8
White XL 0[/pre]
Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016