Today I will explain the very small but very useful features which I use in the past for the procedures. When I am new to sqlserver I am facing many problems this is one of this that I will explain to you today.
That you all know that, User defines Function has limitation that we can not use #temp table or Table variable in UDF. Because of that we can not get the data from another function in the UDF. At that time I find the solution that we are now create the procedure and we get data from that procedure for further manipulation. Question is how to get data from another procedure?. You can get the answer of this question in this post..
e.g., suppose procedure ReturnStudentDetail return the table with two fields Name and City so how can you get that table in another procedure for further manipulation.
–Code
— Create Table
Create table #StudentDetail
(Name varchar (50), City varchar (100))
— Below code give you data in the procedure
Insert into #StudentDetail
Exec ReturnStudentDetail
This syntax works only if you create table like this. You also use Dynamic Sql output for inserting data in #temp table.
— Create Table
Create table #StudentDetail
(Name varchar (50), City varchar (100))
Declare @sql as varchar (500)
Set @sql = ‘Select Name, City from tbl_StudentDetail where ……..’
— Below code give you data in table
Insert into #StudentDetail
Exec (@sql)
So, this is how you can get the data from another procedure or dynamic sql in Table.
Basic thing is whatever the structure return on the basis of that you have to create the table and use that table to get data from procedure or dynamic sql.
I hope this feature is useful for in future. If any query feel free to ask me.