我需要临时表中的一些记录,为此我试图运行以下查询:
DECLARE @temp_table TABLE (Id uniqueidentifier, Dates nvarchar(10))
INSERT @temp_table
SELECT ID,Right(Companies.UserDefined4, 10)
FROM Companies
Select *
From Companies,@temp_table
Where Companies.ID = @temp_table.Id
但是在Where
子句中,我得到了这个错误:
必须声明标量变量@temp_table
正确的代码应该是:
DECLARE @temp_table TABLE (Id uniqueidentifier, Dates nvarchar(10))
INSERT @temp_table
SELECT ID,Right(Companies.UserDefined4, 10)
FROM Companies
Select *
From Companies c
join @temp_table t
on c.ID = t.Id
Try
SELECT *
FROM Companies c
INNER JOIN @temp_table t ON c.ID = t.ID