Avatar of Rickzzz
Rickzzz
 asked on

CROSS APPLY Issue

Not much experience with CROSS APPLY. Running into an issue LEFT JOIN would generally resolve, though not applicable here.

select
 t.refID
 z.dataPiece
from
 MyDataTable t
    CROSS APPLY myFunction(t.refID) z

t.refID may not always be what myFunction expects or is null, therefore those t.records are dropped. So if there's 100 records in MyDataTable, only 90 may result. I can't arbitrarily change t.refID if NULL or not the expected combination of characters (It's a vehicle's VIN btw). I also can't change the function to deal with it, as its used in other applications. Ideally the function would simply return NULL as a JOIN would. Thanks in advance for any assistance.
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Rickzzz

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Máté Farkas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Vitor Montalvão

Why not add a WHERE clause?
select
 t.refID
 z.dataPiece
from
 MyDataTable t
    CROSS APPLY myFunction(t.refID) z 
WHERE t.refID IS NOT NULL

Open in new window

Rickzzz

ASKER
Vitor - thanks for the input.
Rickzzz

ASKER
Thanks!
Your help has saved me hundreds of hours of internet surfing.
fblack61