I would like to get count of specific records. So my query will look like the following…
SELECT
ID,
NAME,
(SELECT...) AS UserCount // Stmt1
FROM MyTable
The issue is that, ‘Stmt1’ is a complex statement and it cannot be written as innerquery.
Well, I can use functions, but the statement includes ‘CREATE TABLE’ so I get the following error message
Cannot access temporary tables from within a function.
What is the best way to accomplish the task ?
You can use user defined table type to solve your problem.
You just create a table variable like
and you can declare this table variable in your function like
On your procedure you can declare your table type like
And you can insert values to this table like
pass this to your function like
please go for this method, thank you