Joining three tables in sql server 2012
-
Dear All we need some help. We have Three Tables in sqlserver2012 Master Table OrderID PackageID CustomerName 1 1 Abc 2 2 Bcd 3 1 xyz Child1 Table OrderID ControlName 1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table)) 1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table)) 1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table)) 2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table)) 2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table)) Child2 Table PackageID Product Color1 Color2 Color3 1 Pant Red Green Blue 1 Shirt Blue Pink Purple 1 Gown Blue Black Yellow 1 T Shirt Red Green White 2 Tie Red Green White 2 Socks Red Green White 2 Bow Red Green White We want to have result like OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow 1 1 ABC Red Blue White x x Blue 2 2 Bcd x x x Green Red DB Script CREATE TABLE [dbo].[Child1]( [Child1ID] [int] NOT NULL, [OrderID] [int] NULL, [ControlName] [nvarchar](max) NULL, CONSTRAINT [PK_Child1] PRIMARY KEY CLUSTERED ( [Child1ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Child2] Script Date: 11/11/2014 6:06:56 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Child2]( [Child2ID] [int] NOT NULL, [PackageID] [int] NULL, [Product] [nvarchar](max) NULL, [Color1] [nchar]
-
Dear All we need some help. We have Three Tables in sqlserver2012 Master Table OrderID PackageID CustomerName 1 1 Abc 2 2 Bcd 3 1 xyz Child1 Table OrderID ControlName 1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table)) 1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table)) 1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table)) 2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table)) 2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table)) Child2 Table PackageID Product Color1 Color2 Color3 1 Pant Red Green Blue 1 Shirt Blue Pink Purple 1 Gown Blue Black Yellow 1 T Shirt Red Green White 2 Tie Red Green White 2 Socks Red Green White 2 Bow Red Green White We want to have result like OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow 1 1 ABC Red Blue White x x Blue 2 2 Bcd x x x Green Red DB Script CREATE TABLE [dbo].[Child1]( [Child1ID] [int] NOT NULL, [OrderID] [int] NULL, [ControlName] [nvarchar](max) NULL, CONSTRAINT [PK_Child1] PRIMARY KEY CLUSTERED ( [Child1ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Child2] Script Date: 11/11/2014 6:06:56 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Child2]( [Child2ID] [int] NOT NULL, [PackageID] [int] NULL, [Product] [nvarchar](max) NULL, [Color1] [nchar]
This isn't how this site works, we will help you where you are stuck. But we dont supply solutions to a requirement. But I would suggest you read up on inner joins[^] and left outer joins[^] the syntax is similar across the different versions on SQL Server. after you have read these and get stuck please show us your code and try to explain why its wrong and we will help you further.
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
Dear All we need some help. We have Three Tables in sqlserver2012 Master Table OrderID PackageID CustomerName 1 1 Abc 2 2 Bcd 3 1 xyz Child1 Table OrderID ControlName 1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table)) 1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table)) 1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table)) 2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table)) 2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table)) Child2 Table PackageID Product Color1 Color2 Color3 1 Pant Red Green Blue 1 Shirt Blue Pink Purple 1 Gown Blue Black Yellow 1 T Shirt Red Green White 2 Tie Red Green White 2 Socks Red Green White 2 Bow Red Green White We want to have result like OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow 1 1 ABC Red Blue White x x Blue 2 2 Bcd x x x Green Red DB Script CREATE TABLE [dbo].[Child1]( [Child1ID] [int] NOT NULL, [OrderID] [int] NULL, [ControlName] [nvarchar](max) NULL, CONSTRAINT [PK_Child1] PRIMARY KEY CLUSTERED ( [Child1ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Child2] Script Date: 11/11/2014 6:06:56 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Child2]( [Child2ID] [int] NOT NULL, [PackageID] [int] NULL, [Product] [nvarchar](max) NULL, [Color1] [nchar]
-
Dear All we need some help. We have Three Tables in sqlserver2012 Master Table OrderID PackageID CustomerName 1 1 Abc 2 2 Bcd 3 1 xyz Child1 Table OrderID ControlName 1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table)) 1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table)) 1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table)) 2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table)) 2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table)) Child2 Table PackageID Product Color1 Color2 Color3 1 Pant Red Green Blue 1 Shirt Blue Pink Purple 1 Gown Blue Black Yellow 1 T Shirt Red Green White 2 Tie Red Green White 2 Socks Red Green White 2 Bow Red Green White We want to have result like OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow 1 1 ABC Red Blue White x x Blue 2 2 Bcd x x x Green Red DB Script CREATE TABLE [dbo].[Child1]( [Child1ID] [int] NOT NULL, [OrderID] [int] NULL, [ControlName] [nvarchar](max) NULL, CONSTRAINT [PK_Child1] PRIMARY KEY CLUSTERED ( [Child1ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Child2] Script Date: 11/11/2014 6:06:56 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Child2]( [Child2ID] [int] NOT NULL, [PackageID] [int] NULL, [Product] [nvarchar](max) NULL, [Color1] [nchar]
I second Eddys suggestion, you're really in for trouble if you keep that table structure.
Wrong is evil and must be defeated. - Jeff Ello
-
Dear All we need some help. We have Three Tables in sqlserver2012 Master Table OrderID PackageID CustomerName 1 1 Abc 2 2 Bcd 3 1 xyz Child1 Table OrderID ControlName 1 Row1COlumn1 (It Means Pant in Red Color is selected by user(relation with Child2 Table)) 1 Row3Column1 (It Means Gown in Blue Color is selected by user(relation with Child2 Table)) 1 Row4Column3 (It Means T Shirt in White Color is selected by user(relation with Child2 Table)) 2 Row1Column2 (It Means Tie in Green Color is selected by user(relation with Child2 Table)) 2 Row3Column1 (It Means Bow in Red Color is selected by user(relation with Child2 Table)) Child2 Table PackageID Product Color1 Color2 Color3 1 Pant Red Green Blue 1 Shirt Blue Pink Purple 1 Gown Blue Black Yellow 1 T Shirt Red Green White 2 Tie Red Green White 2 Socks Red Green White 2 Bow Red Green White We want to have result like OrderID PackageID CustomerName Pant Gown T Shirt Tie Bow 1 1 ABC Red Blue White x x Blue 2 2 Bcd x x x Green Red DB Script CREATE TABLE [dbo].[Child1]( [Child1ID] [int] NOT NULL, [OrderID] [int] NULL, [ControlName] [nvarchar](max) NULL, CONSTRAINT [PK_Child1] PRIMARY KEY CLUSTERED ( [Child1ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Child2] Script Date: 11/11/2014 6:06:56 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Child2]( [Child2ID] [int] NOT NULL, [PackageID] [int] NULL, [Product] [nvarchar](max) NULL, [Color1] [nchar]
Can you redesign your Database tables? It has very bad relations and out put. Why you have 3 columns for Color1, Color2 and Color3 .With this Column how can you get your result .