Simone Spagna
Simone Spagna

Reputation: 21

How to use a custom function in a join clause?

I have a problem with the following statement :

SELECT
      B.idimpianto, 
      B.CodiceImpianto, 
      B.DescrizioneImpianto,
      B.CodiceCDC, 
      B.descrizioneCDC
FROM ITCOWBase.dbo.GetImpiantiUtente(B.idimpianto) AS A 
INNER JOIN dbo.vImpianti AS B ON A.idimpianto = B.idimpianto

When I try to execute it, the SQL parser says:

the multipart identifier B.impianto could not be bound.

Upvotes: 0

Views: 592

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

You want apply:

SELECT     B.idimpianto, B.CodiceImpianto, B.DescrizioneImpianto,
           B.CodiceCDC, B.descrizioneCDC
FROM dbo.vImpianti b cross apply
     ITCOWBase.dbo.GetImpiantiUtente(B.idimpianto) 

It looks like you are only doing filtering, so you want cross apply rather than outer apply.

Upvotes: 1

Related Questions