Hi,I have 2 tables. Temp and PolicyDetails. I have to return according to customers all what is in temp but also have policy with coverage 234 in policyDetails.Result:customerid policyid coverageid1 1 801 2 2344 3 2347 4 1807 5 2346 4 234USE [TestDB]GO/****** Object: Table [dbo].[temp] Script Date: 05/11/2013 12:02:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[temp]( [id] [int] IDENTITY(1,1) NOT NULL, [CustomerID] [int] NULL, [PolicyId] [int] NULL, CONSTRAINT [PK_temp] PRIMARY KEY CLUSTERED ( [id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET IDENTITY_INSERT [dbo].[temp] ONINSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (1, 1, 1)INSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (2, 2, 1)INSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (3, 3, 2)INSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (4, 4, 3)INSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (5, 7, 5)INSERT [dbo].[temp] ([id], [CustomerID], [PolicyId]) VALUES (6, 6, 4)SET IDENTITY_INSERT [dbo].[temp] OFF/****** Object: Table [dbo].[PolicyDetails] Script Date: 05/11/2013 12:02:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[PolicyDetails]( [id] [int] IDENTITY(1,1) NOT NULL, [CustomerId] [int] NULL, [PolicyId] [int] NULL, [CoverageId] [int] NULL, [ContractId] [int] NULL, CONSTRAINT [PK_PolicyDetails] PRIMARY KEY CLUSTERED ( [id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET IDENTITY_INSERT [dbo].[PolicyDetails] ONINSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (1, 1, 1, 80, 78)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (2, 2, 1, 45, 234)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (3, 1, 2, 234, 78)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (4, 3, 2, 4567, 890)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (5, 1, 3, 234, 890)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (6, 4, 3, 234, 890)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (7, 5, 1, 746, 78)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (8, 6, 4, 234, 78)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (9, 4, 3, 567, 890)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (10, 7, 5, 234, 78)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (11, 7, 5, 789, 34)INSERT [dbo].[PolicyDetails] ([id], [CustomerId], [PolicyId], [CoverageId], [ContractId]) VALUES (12, NULL, 4, 6780, 323)SET IDENTITY_INSERT [dbo].[PolicyDetails] OFF
Thanks