Reputation: 505
Is it possible to define a column datatype as table in a table variable in SQL Server? like i tried this code
Declare @master table(
idx int identity(1,1),
ID int,
Title nvarchar(250),
IntegratedAccounts table(
AccountID int,
AccountTitle nvarchar(250)
)
)
I want to retrieve a result set from my table variable to populate DataTable in c# that structured as :
var dt = new DataTable();
dt.Columns.Add("idx", typeof(int));
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("IntegratedAccounts", typeof(DataTable));
Upvotes: 2
Views: 1467
Reputation: 9729
Answer is no you cannot in SQL. Simple as that :)
However you can relate to tables to achieve the same result with help of foreign keys
So to achieve
table( (idx int identity(1,1), ID int, Title nvarchar(250), IntegratedAccounts table( AccountID int, AccountTitle nvarchar(250) ) )
you can make 2 tables
table (idx int identity(1,1), ID int, Title nvarchar(250), account_id)
and
table2(AccountID int, AccountTitle nvarchar(250) )
and have your table.account_id references to table2.AccountID
That may help you achieve what you want to..
Upvotes: 2