how to use join with temp table
how to use join with temp table
CREATE TABLE [dbo].[NormalTable](
[Id] [int] NULL,
[name] [nvarchar](50) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[NormalTable] ([Id], [name]) VALUES (1, N'range1')
GO
INSERT [dbo].[NormalTable] ([Id], [name]) VALUES (2, N'Range2')
GO
INSERT [dbo].[NormalTable] ([Id], [name]) VALUES (3, N'Range3')
GO
CREATE TABLE #Temp
([id] int, [date] date, [score] int)
;
INSERT INTO #Temp
([id], [date], [score])
VALUES
(1, '2013-04-13', 100),
(2, '2013-04-14', 92),
(3, '2013-04-15', 33)
;
SELECT N.* FROM NormalTable N
LEFT JOIN #Temp T ON N.id = T.ID
CREATE TABLE #Temp
([index] INT,minVal DECIMAL(18,2),maxVal DECIMAL(18,2))
INSERT INTO #Temp
([index], [minVal], [maxVal])
Share This with your friend by choosing any social account