tsql - T-SQL Set (assign) Function Result in SELECT -


i need know how set return value function can used again in same query.

the problem:

select a.field1,  a.field2, [thefunction](id,3.4,'test') sumofaverages, [thefunction2]([thefunction](id,3.4,'test'), 1,2)) summary ... 

you can see putting in function again in function2 parameter, set variable not need this.

i have tried doing

[thefunction](id,3.4,'test') sumofaverages, [thefunction2](sumofaverages, 1,2)) summary 

i don't mind doing in outer select not want join on inner select have fields acquire results.

i appreciate help

thanks

you should able shifting first function separate select clause. typical ways achieve use cte, subquery, or apply. like:

select a.field1,  a.field2, t.sumofaverages, [thefunction2](t.sumofaverages, 1,2)) summary <existing tables> cross apply (select thefunction(id,3.4,'test') sumofaverages) t 

the reason within each select clause, system meant able evaluate column expressions in parallel - language prohibits dependencies between expressions.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -