I'm using SQL Server 2008 and I have a SP that looks like this:
SELECT id = t.nTableId
,t.nTableId AS id2
,t.nTableId
FROM dbo.table AS t
I'm using a .NET application where I want the column names: id, id2 and nTableId.
Right now I'm using sp_helptext to get the SP as a list of strings
var columns = new List<string>();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
columns.Add(reader.GetString(0));
}
}
In this list of strings I'm trying to find SELECT and FROM, and then take the rows between these two. These rows do I format so that it looks correct afterwards.
Then problem is that I don't find this solution good enough. Do you guys have any tips that would work for SQL Server 2008 to retrieve the column names id, id2 and nTableId in this case.