简体   繁体   中英

SQL Database Rows to GridView Columns

I have a few database tables set up like:

Executions
-ExecutionID

Periods
-PeriodID
-ExecutionID

Transactions
-TransactionID
-PeriodID
-Name
-ResponseTime

I have a page where I want to display the execution in a GridView, with columns:

TransactionName, Period1ResponseTime, Period2ResponseTime, etc..

I've been trying to come up with the best way to combine the tables in to a single datasource to feed to the GridView but am only coming up dirty brute force ideas. What do you think the best approach for this would be? Is it possible using SQL alone?

Ps. The transaction names are distinct per period (won't be 2 transactions with same name in a period) and not every period will have the same transactions although they're mostly the same (different response times) though.

I ended up doing it the brute force c# approach as I can't figure out the complex SQL involved - not really sure what "tools" I could use to accomplish. That said I'll have to look more in to cursors. Basically what I do now is 1 query to get all distinct transaction names from periods in the execution (make SQL statement on the fly with some OR appends. Then get transactions for the different period and store in an array. Finally I combine them all in to a custom data table by going row by row (distinct transaction names), and for each period search its the transaction list for that name: if found puts the response time value in that periods column, otherwise leaves blank. Not sure what the duration is for stackoverflow questions but if anyone has a suggestion to improve on this approach I'm all ears since it feels very inefficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM