| Author |
Topic |
|
Shilpa22
Starting Member
37 Posts |
Posted - 2010-04-24 : 08:54:39
|
| Hi All,I have procedure in which I have 1 select statement which returns a set of rows. Ex result set: AccountName StartDateaaa 22/04/10bbb 23/04/10ccc 24/04/10ddd 15/04/10eee 26/04/10Now from the above result set I need a row which have MIN(StartDate).I need both these results. Using C# I need to retrieve this data.Can anyone please help me.give me an example. How to achieve this..Thanks,ShilpaThanks in AdvanceShilpa |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 08:58:28
|
| [code]SELECT * FROM Table WHERE StartDate IN (SELECT MIN(StartDate) FROM Table)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Shilpa22
Starting Member
37 Posts |
Posted - 2010-04-24 : 09:02:12
|
| Hi,Thanks for your reply.select * from table meaning???First result set is a dynamic result set. I need to query on that resultset. How can I do that?ThanksThanks in AdvanceShilpa |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 09:12:55
|
| which dynamic set?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Shilpa22
Starting Member
37 Posts |
Posted - 2010-04-24 : 09:24:35
|
| With the first select statement, I will get a dynamic result set which luks like below,AccountName StartDateaaa 22/04/10bbb 23/04/10ccc 24/04/10ddd 15/04/10eee 26/04/10Again I need MIN(StartDate) from the above result. SO totally I want prcedure to return the set of account names (first result set) and also the MIN(DATE).Pls help me..Thanks in AdvanceShilpa |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 09:31:05
|
| whats the current query you're using?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Shilpa22
Starting Member
37 Posts |
Posted - 2010-04-24 : 09:52:06
|
| SELECT account_id, query_start_time FROM (SELECT account_id, query_start_time, Row_number() OVER(PARTITION BY account_id ORDER BY query_start_time) rn FROM dws..dws_job_query where account_id like '%Dss_stage%') t WHERE rn = 1 It returns the first result set. Based on this I need to get MIN(Date) rowThanks in AdvanceShilpa |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-24 : 11:10:20
|
| [code]SELECT account_id, query_start_time,MinDate FROM (SELECT account_id, query_start_time, Row_number() OVER(PARTITION BY account_id ORDER BY query_start_time) rn,MIN(query_start_time) OVER () MinDate FROM dws..dws_job_query where account_id like '%Dss_stage%') t WHERE rn = 1 [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2010-04-24 : 14:05:38
|
[code]SELECT account_id, MIN(query_start_time)FROM dws..dws_job_queryWHERE account_id like '%Dss_stage%'GROUP BY account_id[/code] Hope can help...but advise to wait pros with confirmation... |
 |
|
|
|