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 |
|
BendJoe
Posting Yak Master
128 Posts |
Posted - 2008-10-20 : 10:45:33
|
| Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'from'.I am getting this for the following stored proc.( @count int )ASBEGINDeclare @GroupTypeID int;Declare @SQL varchar(2000);Select @GroupTypeID =GroupTypeID from GroupType Where Code='EXP'Select GroupCategoryID into #GroupCategory from GroupCategory where GroupTypeID=@GroupTypeIDSelect GroupID into #Groups from Groups where GroupCategoryID in (Select GroupCategoryID from #GroupCategory)Select ArticleID into #Articles from ArticleGroupLink where GroupID in (Select GroupID from #Groups)Set @SQl ='Select top '+convert(varchar,@count)+' from Articles where ArticleID in (Select ArticleID from #Articles) order by ActiveDate desc'Exec(@SQL) ENDGOPlease Help |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-20 : 10:47:03
|
..."TOP x FROM Articles..."You need some columns here to return. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-20 : 10:48:26
|
Always make it a practise to PRINT @SQL before EXEC (@SQL).That way you will see the code executed in next step. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
BendJoe
Posting Yak Master
128 Posts |
Posted - 2008-10-20 : 10:48:37
|
| Can I use Set @SQl ='Select top '+convert(varchar,@count)+' * from Articles where ArticleID in (Select ArticleID from #Articles) order by ActiveDate desc' |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-20 : 10:50:25
|
Try. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
BendJoe
Posting Yak Master
128 Posts |
Posted - 2008-10-20 : 10:50:33
|
| Thanks worked |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-20 : 10:51:48
|
quote: Originally posted by BendJoe Can I use Set @SQl ='Select top ('+convert(varchar,@count)+') * from Articles where ArticleID in (Select ArticleID from #Articles) order by ActiveDate desc'
you can but whats the purpose of converting @count to varchar? its hould be integer. Also use () if using SQL 2005 or later |
 |
|
|
|
|
|