Question : 2 selects in a stored proc

Is it possible to have 2 seperate queries in a stored proc?   If so,  how would you call the seperate tables created (assuming they all had different field names)?  
 
Would it be better to create the 2 tables and then join them?   If so, how would i do this?

Answer : 2 selects in a stored proc

Yes, its possible to to get two seperate result sets from a stored procedure in .Net.

Using DataAdapter fill a DataSet and access each result set as DataTable from DatSet using index. Following is the sample code:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
System.Data.SqlClient.SqlConnection objSqlConnection = new System.Data.SqlClient.SqlConnection("your connection string comes here");
                                System.Data.SqlClient.SqlCommand objSqlCommand = new System.Data.SqlClient.SqlCommand();
                                lobjSqlCommand.Connection = objSqlConnection;
System.Data.SqlClient.SqlDataAdapter objSqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter(objSqlCommand);
                                DataSet dsData = new DataSet();
                                objSqlCommand.CommandText = "your stored procedure name comes here";
                                objSqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                                objSqlDataAdapter.Fill(dsData);

                                DataTable dtAllJobs = dsData.Tables[0];
                            DataTable dtEmailIDs = dsData.Tables[1];
//...like that you can access any number of result set from a Stored procedure or query.
Random Solutions  
 
programming4us programming4us