> Thank you for your reply. I am using Sql Server 2000
2000 only accept a constant for the value of TOP. You would have to use dynamic SQL or SET ROWCOUNT
for anything else. 2005 accepts a variable or a scalar subquery.
"Rich" <Rich@discussions.microsoft.com> wrote in message
news:73F9C1FC-A560-434D-B245-F77CF993BFA9@microsoft.com...
> Thank you for your reply. I am using Sql Server 2000
>
> I realize thatt I could do this:
>
> Select top 25 percent * from tbl1
>
> But the exercise is to find syntax to do something like this:
>
> select top (select count(*)/4 from temp1b) * from temp1b
>
> When I tried this I got 2 error messages that just said
> syntax error near "(" and syntax error near *
>
> just to see it if is doable - for other purposes.
>
> The idea is to not have to include these lines
> Declare @i int
> Select @i = Count(*)/4 from tbl1
>
> Is something like what I am trying to do feasable?
>
> "Kalen Delaney" wrote:
>
>> What version are you using? What does 'no luck' mean? Did you get an error
>> message? What did it say?
>>
>> SQL Server 2005 lets you use an expression with TOP, but the expression,
>> even if just a variable, must be in parenthesis.
>>
>> SELECT TOP(@i) * FROM temp1b
>>
>> However, you might also consider trying a simple percentage, which is
>> available in SQL 2000:
>>
>> SELECT TOP 25 PERCENT FROM temp1b
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>>
http://sqlblog.com >>
>>
>> "Rich" <Rich@discussions.microsoft.com> wrote in message
>> news:9BC2660F-A948-4F45-81FB-2A0C23320027@microsoft.com...
>> > Greetings,
>> >
>> > I need to select a quarter of the rows from a table. I tried this syntax
>> > with no luck
>> >
>> > select top (select count(*)/4 from temp1b) * from temp1b
>> >
>> > my alternative is to do this:
>> >
>> > Declare @i int
>> > Select @i = Count(*)/4 From tbl1
>> > Select top @i * from tbl1
>> >
>> > What is the correct synatxt to do is using this version?
>> > select top (select count(*)/4 from temp1b) * from temp1b
>> >
>> > Thanks,
>> > Rich
>>
>>
>>