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 |
|
kalyformin
Starting Member
15 Posts |
Posted - 2007-12-12 : 18:25:00
|
| I have a stored procedure that takes in a parameter - @count.Within thIS stored procedure I have a statement that selects the distinct Top "n" records. How can I set the query to get something like this?SELECT distinct top <@count>FROM TABLE |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-12 : 18:34:17
|
| What version of SQL Server are you using?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
kalyformin
Starting Member
15 Posts |
Posted - 2007-12-12 : 18:40:51
|
| SQL Server 2000 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-12 : 18:45:11
|
| http://www.sqlteam.com/article/dynamic-sql-or-how-do-i-select-top-var-recordsTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
kalyformin
Starting Member
15 Posts |
Posted - 2007-12-12 : 19:00:13
|
| Thanks.Is there anyway I can implement this with the following query- INSERT <Table1>(col1,col2)SELECT distinct TOP <@count> col1, col2FROM <Table2> |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-12 : 19:04:01
|
| Yes. Check out the article and then try the two solutions out.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|
|
|