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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-01-21 : 08:06:51
|
| sreenivas writes "SQL SERVER VERSION:2000I AM FACING ONE PROBLEM WHILE I AM DEVELOPING MY APPLICATION ON .NET..IT REQUIRES THAT TO RETRIEVE EXACT RECORD FROM TOPIN THE TABLE i.e., 3rd record or 5th record BY USING DYNAMIC QUERY..TO ACCEPT NUMBER FROM THE USER ,I HOPE THERE IS NO REQUIREMENT FOR TABLE FILEDS..WHAT EVER THE FIELDS." |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2004-01-21 : 08:15:40
|
| [code]declare @top intdeclare @sql varchar(1000)set @sql = ''set @top = 5 -- user inputset @sql = @sql + 'SELECT TOP ' + cast(@top as varchar(20)) + ' FROM myTable ORDER BY someField'exec (@sql)[/code]________________Make love not war! |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-01-21 : 08:25:16
|
| with a * to get the record though.And to get the single recdeclare @top intdeclare @sql varchar(1000)set @sql = @sql + 'select top 1 * from (SELECT TOP ' + cast(@top as varchar(20)) + ' * FROM myTable ORDER BY someField) a order by someField desc'exec (@sql)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|