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 - 2002-03-31 : 22:40:37
|
| Jessica writes "Hi there,I have read the thread from 8/1/2000 about using TOP and putting the entire SQL statement as a variable following the example stated. I am trying to get the top 5 posted threads from a forum to display as links on an index.However I keep getting a Syntax error after the number of the @numrows. I am using SQL 6.5 and I couldn't even find any help about using TOP but the topic was there in SQL 2000.This is my query and my error:declare @vSQL varchar(255), @numrows intselect @numrows = 5SELECT @vSQL = 'SELECT TOP ' + CONVERT(varchar, @numrows) + ' * FROM FORUM_TOPICS a, FORUM_FORUM b WHERE a.FORUM_ID = b.FORUM_ID ORDER BY a.T_LAST_POST ASC'Execute (@vSQL)My error I get is:(1 row(s) affected)(1 row(s) affected)Msg 170, Level 15, State 1Line 1: Incorrect syntax near '5'.Any idea why there is a syntax error there?Thank you in advance for any suggestion or help with this topic." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-03-31 : 23:14:57
|
| top isn't available with v6.5 - it came in with v7.you can do the same thing with set rowcount and use temp tables instead of subqueries.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|