Skip to content
Advertisement

SQL Table Valued Function – Return certain data from ‘WITH’ based on parameter value

I am trying to do a “with” to loop through some data (which its doing fine). But after that with, I want to return data dependent on a bit parameter. Its important that this is inside a function. Below is basically what my code is doing.

After this, I am trying to do something like

SQL is not my strength and I am still learning sorry. I am also unsure whether or not to use inline or multi statement function

EDIT: When I am giving the case, I am using it to explain what I am after to return, not necessarily what I will use. I use it to just describe what I need using what little I know if that makes sense.

Advertisement

Answer

You can do as follows. This is just one of the solution. you can do with many other ways also.

After creation of CTE, try with following

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