SQL Rows Join...
-
I have one table CREATE TABLE #T1(id int,Name varchar(10)) insert into #T1 (id,Name) values (1,'Haris') insert into #T1 (id,Name) values (2,'Arshad') CREATE TABLE #T2(id int,Reason varchar(5)) insert into #T2 (id,Reason) values (1,'X') insert into #T2 (id,Reason) values (2,'Y') insert into #T2 (id,Reason) values (1,'Z') insert into #T2 (id,Reason) values (1,'X') Now i need output like Id Name Reason1 Reason2 Reason3 ......ReasonN 1 Haris X Z X 2 Arshad Y NULL NULL Amit
-
I have one table CREATE TABLE #T1(id int,Name varchar(10)) insert into #T1 (id,Name) values (1,'Haris') insert into #T1 (id,Name) values (2,'Arshad') CREATE TABLE #T2(id int,Reason varchar(5)) insert into #T2 (id,Reason) values (1,'X') insert into #T2 (id,Reason) values (2,'Y') insert into #T2 (id,Reason) values (1,'Z') insert into #T2 (id,Reason) values (1,'X') Now i need output like Id Name Reason1 Reason2 Reason3 ......ReasonN 1 Haris X Z X 2 Arshad Y NULL NULL Amit
I'm not sure that is possible. The best I can think of is to join to make the output like this: Haris X Haris Z Haris X Arshad Y Once you get your data into a DataTable, you can manipulate it so that when it displays in a DataGrid it looks like the output you want. The problem is, there is no way to how many Reasons there are for each Name. So there is no way to make an output table that has an undetermined number of columns.
-
I'm not sure that is possible. The best I can think of is to join to make the output like this: Haris X Haris Z Haris X Arshad Y Once you get your data into a DataTable, you can manipulate it so that when it displays in a DataGrid it looks like the output you want. The problem is, there is no way to how many Reasons there are for each Name. So there is no way to make an output table that has an undetermined number of columns.
No looking for SQL Solution. I posted here becuase not got much reply from SQL forum....Thanks any way!!
-
No looking for SQL Solution. I posted here becuase not got much reply from SQL forum....Thanks any way!!
Hi u have to make use of function returning table with in sql server where you have to pass the id.
Hello Forum Always be in touch to help about the topic ASP.NET
-
I have one table CREATE TABLE #T1(id int,Name varchar(10)) insert into #T1 (id,Name) values (1,'Haris') insert into #T1 (id,Name) values (2,'Arshad') CREATE TABLE #T2(id int,Reason varchar(5)) insert into #T2 (id,Reason) values (1,'X') insert into #T2 (id,Reason) values (2,'Y') insert into #T2 (id,Reason) values (1,'Z') insert into #T2 (id,Reason) values (1,'X') Now i need output like Id Name Reason1 Reason2 Reason3 ......ReasonN 1 Haris X Z X 2 Arshad Y NULL NULL Amit
Hi There Do u know about DataRelation? U can do it using datarelation follow step select all rows of table one and bind dataset ie. ds1 select all rows of table two with relation of table one like T1.Id=T2.Id and bind dataset ie. ds2 Now use datarelation ie.
DataRelation dr = new DataRelation("new_relation", ds1.Tables[0].Columns[0], ds2.Tables[0].Columns[0]); ds1.Relations.Add(dr);
Make sure both ds have same column[0] Best Regard Pathan---------------------------------------------------