我在SQL Server的存储过程中有以下查询:
SELECT TLI.LESNumber
,COUNT(TLT.PL)
INTO #PWCM
FROM #tmpLESImport TLI
INNER JOIN tbl_LES L
on TLI.LESNumber=L.NUMB
WHERE ISNULL(L.DELT_FLAG,0)=0
AND L.SCHL_PK=@SCHL_PK
AND TLI.PL IS NOT NULL
AND LEN(TLI.PL)>0
GROUP BY LESNumber
HAVING COUNT(PL)>1
运行查询时,出现以下错误:
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
谁能告诉我为什么?直到此查询,
#PWCM
才会出现在任何地方。 最佳答案
当您对表进行SELECT INTO
编码时,它会创建表(在本例中为临时表)。为了创建表,每列都需要一个名称,而count
列则不需要。您只需要给它起一个名字:
SELECT TLI.LESNumber,COUNT(TLT.PL) [NumRecords]
INTO #PWCM
FROM #tmpLESImport TLI
...
关于使用 'An object or column name is missing or empty'的SQL Server查询错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24998586/