Skip to content
Advertisement

How do i use a selected column as a variable for the next selection of the same sub-query

I am trying write a query to create a report and for the report, I need to get the manager of the user who created a form on our system. Because the system is old and changed a lot, there is no easy way to get the manager of the user or get their manager from the time when they created the form. So, the person before me created a function for the job but it is costly. It takes way too long to get a result from the function fn_getUserMan. I want to call the function once and then use the result on my other selections as a variable and because it is dependent on Frm, I cannot take it out of the sub-query and have it on the main query and set it on a local variable and sql wont let me set the variable on the sub-query.

So my question is this: Is it possible to use FnMAN in my next selection as i tried in the query. It says Invalid column name 'FnMAN'. when i try it like in the query.

In the code block, it seems like i need it only twice but i actually need it a lot more. I need to check the result and if its some person A, i need to make it some person B like i did with John and Jane. So i really need to make this faster.

Advertisement

Answer

I found the solution with LEFT JOIN and added a new column to use as a result of FnMAN. I dont know whether or not this is a healthy way of having a a solution but it works.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement