我在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在此查询之前不会出现在任何地方。
#PWCM
当您SELECT INTO使用表时,它将创建表(在本例中为临时表)。为了创建表,每列都需要一个名称,而您的count列则不需要。您只需要给它起一个名字:
SELECT INTO
count
SELECT TLI.LESNumber,COUNT(TLT.PL) [NumRecords] INTO #PWCM FROM #tmpLESImport TLI ...