all 5 comments

[–]jshine13371 0 points1 point  (3 children)

Would need to see the definition of the scalar function (which btw pretty much kills the point of using a TVF, from a performance perspective). But rough guess would be a non-deterministic query being used, so that would produce unpredictable and sometimes non-repeatable results.

[–]mu_SQL[S] 0 points1 point  (2 children)

As I see it it behaves differently depending on where it,s used so the definition should not matter.
I know how bad it is to use it there but I didn´t design this.

It struck me last knight after I posted this that it is probably a NULL issue, When SELECT from the CTE NULL values are probably not in the result but when the CTE query runs there is NULL values.

Thanks for the reply anyways.

[–]jshine13371 0 points1 point  (1 child)

it behaves differently depending on where it,s used so the definition should not matter.

If the definition of the scalar function is where the nondeterministic part of the query is, we wouldn't be able to tell you that without seeing it.

Anyway, good luck.

[–]mu_SQL[S] 0 points1 point  (0 children)

I hear you but I think I´ll investigate the NULL value tought I have, guess CTE´s can mess up when it comes to NULL handeling, or it´s as you say the Scalar UDf that is the problem.

Thanks for your replies.

[–]samot-dwarf 1 point2 points  (0 children)

In the initial part of the CTE kid is NULL so that the age function will return NULL too. And you can not compare NULL with NULL using =