SQL Server 查询错误,“对象或列名丢失或为空”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24998586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server query erroring with 'An object or column name is missing or empty'
提问by Art F
I have the following query in a stored procedure in SQL server:
我在 SQL 服务器的存储过程中有以下查询:
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
When the query is run I get the following error:
当查询运行时,我收到以下错误:
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.
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.
Can anyone tell me why? #PWCM
does not appear anywhere until this query.
谁能告诉我为什么?#PWCM
在此查询之前不会出现在任何地方。
回答by Joe Enos
When you SELECT INTO
a table, it creates the table (in this case, a temp table). In order to create a table, each column needs a name, which your count
column does not. You just need to give it a name:
当您SELECT INTO
创建一个表时,它会创建该表(在本例中为临时表)。为了创建表,每一列都需要一个名称,而您的count
列不需要。你只需要给它一个名字:
SELECT TLI.LESNumber,COUNT(TLT.PL) [NumRecords]
INTO #PWCM
FROM #tmpLESImport TLI
...
回答by Yossi Vainshtein
I had this error for this query
我在这个查询中遇到了这个错误
SELECT
CASE WHEN COALESCE([dbo].[my-table].[field],"") = '...' THEN 'A'
WHEN COALESCE([dbo].[my-table].[field],"") = '...' THEN 'B'
...
END AS aaa INTO ##TEMPTABLE
FROM [dbo].[my-table]
Turns out I had to change the ""
inside the COALSCE into ''
.
原来我不得不""
将 COALSCE 内部更改为''
.
Solved it for me
为我解决了