Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
genius_palli
Starting Member
42 Posts |
Posted - 2008-12-01 : 02:06:39
|
Hi Everyone..In MS Access, we have DMin function, do we have any equivalent function in SQL Server. Or is there any other way to do the same job.Please help. Thanks in advance for your suggestions.Every experience has something to learn. Go get it.* Thanks and Regards *genius_palliWeb Developer |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-01 : 02:13:27
|
nope you need to write query for that likeSELECT Min(column) FROM tableWHERE condition |
 |
|
genius_palli
Starting Member
42 Posts |
Posted - 2008-12-01 : 05:36:41
|
Thanks buddy... :-)Every experience has something to learn. Go get it.Thanks and Regardsgenius_palliWeb Developer |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-01 : 05:42:27
|
With SQL Server 2005 and later, you can use the windows functions to PARTITION BY same thing. E 12°55'05.63"N 56°04'39.26" |
 |
|
genius_palli
Starting Member
42 Posts |
Posted - 2008-12-01 : 07:44:39
|
Hi Peso..Could you please define bit in detail how to use the windows functions.Frankly speaking , i had got the solution to my problem by writing subquery for DMin function as Visakh16 suggested.But I just want to learn about windows functions.Thanks lot for replying.Every experience has something to learn. Go get it.Thanks and Regardsgenius_palliWeb Developer |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-01 : 07:54:31
|
[code]DECLARE @Sports TABLE ( Team VARCHAR(20), Region VARCHAR(20), Points INT )INSERT @SportsSELECT 'AIK', 'Stockholm', 49 UNION ALLSELECT 'Djurgården', 'Stockholm', 40 UNION ALLSELECT 'Elfsborg', 'Västra', 50 UNION ALLSELECT 'GAIS', 'Västra', 27 UNION ALLSELECT 'Gefle', 'Norra', 31 UNION ALLSELECT 'Göteborg', 'Västra', 36 UNION ALLSELECT 'Häcken', 'Västra', 22 UNION ALLSELECT 'Halmstad', 'Västra', 27 UNION ALLSELECT 'Hammarby', 'Stockholm', 43 UNION ALLSELECT 'Helsingborg', 'Södra', 42 UNION ALLSELECT 'Kalmar', 'Östra', 41 UNION ALLSELECT 'Malmö', 'Södra', 38 UNION ALLSELECT 'Örgryte', 'Västra', 17 UNION ALLSELECT 'Öster', 'Östra', 19SELECT Team, Points, Region, ROW_NUMBER() OVER (ORDER BY Points DESC) AS TotPl, RANK() OVER (ORDER BY Points DESC) AS TotRank1, DENSE_RANK() OVER (ORDER BY Points DESC) AS TotRank2, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY Points DESC) AS RgnPl, RANK() OVER (PARTITION BY Region ORDER BY Points DESC) AS RgnRank1, DENSE_RANK() OVER (PARTITION BY Region ORDER BY Points DESC) AS RgnRank2, MAX(Points) OVER (PARTITION BY Region) AS RgnMax, NTILE(3) OVER (ORDER BY Points DESC) AS LayerFROM @SportsORDER BY Points DESC[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
genius_palli
Starting Member
42 Posts |
Posted - 2008-12-02 : 03:35:22
|
It seems to be looking great.. I have used table variables but not these Windows functions.Thanks Peso for your reply, i will try to use them.Every experience has something to learn. Go get it.Thanks and Regardsgenius_palliWeb Developer |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-02 : 04:14:25
|
The use of table variable is only to get sample data because I have no access to your data. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|