Link to home
Start Free TrialLog in
Avatar of btcexch
btcexch

asked on

how to Combine result from 3 Separate query in one gridview

how to Combine  result from 3 Separate  query  in one gridview in C# And ASP.net
Example:
query1 result: 03:04
query2 result: 12:45
query3 result: 04:13

Gridview
query1 |query2  |query3
03:04|12:45|04:13
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you need to tell us what's the original tables from your queries so that we can suggest a solution for you.

also tell us what database you're using as it could have different approaches available
One possible solution showing results as rows:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="result" HeaderText="Result" />
    </Columns>
</asp:GridView>

Open in new window

var ls=new List<string>();
ls.Add("03:04"); //query1 
ls.Add("12:45"); //query2 
ls.Add("04:13 "); //query3 
gv.DataSource=ls.Select (l =>new{result=l});
gv.DataBind();

Open in new window

Basically code adds the query results into a  list of strings  that is assigned as grid view data source.
Avatar of btcexch
btcexch

ASKER

Ryan Chong : my database Mysql
select SEC_TO_TIME(sum(TIMESTAMPDIFF(second,reports.inone,date_FORMAT(reports.inone,'%Y-%m-%d 08:00:00') ))) AS early FROM `wave`.`reports` where personnelnr = 12793 and reportdate between '2015/09/01' and '2015/09/30' and date_FORMAT(reports.inone, '%T') < '08:00:00' and time_to_sec(reports.inone) < 28200"

Open in new window

SELECt SEC_TO_TIME( sum(TIME_TO_SEC(reports.lateone ))) AS Late FROM `wave`.`reports` where  personnelnr = 12793 and reportdate between '2015/09/01' and '2015/09/30' and reports.lateone >= '00:10:00' Order by personnelnr "

Open in new window

select  personnelnr,SEC_TO_TIME( sum(TIME_TO_SEC(reports.otone))) AS Excess FROM `wave`.`reports` where  personnelnr=12793 and reportdate between '2015/09/01' and '2015/09/30'and reports.otone >= '00:10:00'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of btcexch

ASKER

Thank you a lot .. Excellent Solution