Error "No column name was specified"

Asked

Viewed 1,350 times

1

Could someone please let me know why you made that mistake?

"Msg 8155, Level 16, State 2, Line 26 No column name was specified for column 1 of 'A'. Msg 8155, Level 16, State 2, Line 42 No column name was specified for column 1 of 'B'."

Follow the query and part of the error :

OUTER APPLY (SELECT CONCAT(TT.NUMSERI,TT.PRODUTO ,MAX(TT.DATA)) 
                FROM TLX_INVENTORY_TRANS_HIST AS TT WITH (NOLOCK)
                    WHERE TT.PRODUTO = FN.PRODUTO AND TT.NUMSERI = FN.NUMSERI
                        GROUP BY TT.NUMSERI,TT.PRODUTO,TT.DATA)AS A

OUTER APPLY (SELECT CONCAT(TT.NUMSERI,TT.PRODUTO ,MIN(TT.DATA)) 
                 FROM TLX_INVENTORY_TRANS_HIST AS  TT WITH (NOLOCK)
                    WHERE TT.PRODUTO = FN.PRODUTO AND TT.NUMSERI = FN.NUMSERI
                        GROUP BY TT.NUMSERI,TT.PRODUTO,TT.DATA)AS B
  • OUTER APPLY?! Got the topic’s answer https://answall.com/questions/273763/optimiza%C3%A7%C3%a3o-de-query-sql-server ?

  • Yes.. but where in that stretch? that Outer apply are two subquerys of a larger one

  • Yeah, take this OUTER APPLY and put LEFT JOIN. It gets simpler. See the answer in the linked topic.

  • LEFT JOIN in this case does not answer me, I took the test before making an Outer apply

1 answer

2

It is necessary that the expressions present in the sub-consultations are named. For example:

-- código #1
... (SELECT CONCAT(TT.NUMSERI,TT.PRODUTO ,MAX(TT.DATA)) as SERI_PROD_DATA
                FROM TLX_INVENTORY_TRANS_HIST AS TT WITH (NOLOCK)
                    WHERE TT.PRODUTO = FN.PRODUTO AND TT.NUMSERI = FN.NUMSERI
                        GROUP BY TT.NUMSERI,TT.PRODUTO,TT.DATA) as A
  • Thank you very much!

  • It worked But when I call them keeps giving this error : The multi-part Identifier "TT.DATA" could not be bound. Msg 4104, Level 16, State 1, Line 19 The multi-part Identifier "TT.DATA" could not be bound. CAST(TT.DATA AS DATETIME) PRIMEIRA_DATA, CAST(TT.DATA AS DATETIME) SEGUNDA_DATA,

  • The sub-query generated by code #1 has alias A. The error message you transcribed cites alias TT and in a completely different context. These are errors from different sources; better open another topic for this new error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.