SQL Server query erroring with 'An object or column name is missing or empty'
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 TLI.LESNumber,COUNT(TLT.PL) [NumRecords]INTO #PWCMFROM #tmpLESImport TLI...
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 ##TEMPTABLEFROM [dbo].[my-table]
Turns out I had to change the ""
inside the COALSCE into ''
.
Solved it for me