Tuesday, March 1, 2011

How do I return multiple datatables from a SQL Server stored procedured?

I need to make two queries on two different tables and the data isn't really related. So when I call the stored proc through my code, I should be getting a DataSet with two DataTables, one DataTable for each query. How is that done in SQL Server stored procs?

From stackoverflow
  • Simply execute two SELECT statements in the proc:

    SELECT * FROM Foo
    SELECT * FROM Bla
    

    when you then Fill() a dataset, you'll get two datatables, one with the first resultset, the other with the second.

    MarlonRibunal : you may want to specify the columns for performance purposes. Like, select column1, column2, etc...
    Frans Bouma : I know. It was just an example.
    edosoft : Make sure to add SET NOCOUNT ON or your client will see the 'x rows effected' as another resultset.

0 comments:

Post a Comment