471,049 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Select top (7 - (datepart(weekday, Fordate))) from table1

Is there any way to get 'x' rows using a computed value in the 'SELECT TOP' clause. I know of the 'rowcount' way but that doesnot solve the problem as I am making this query in XML.

Please HELP!

Regards,
Not a DBA yet
May 23 '07 #1
1 2199
almaz
168 Expert 100+
Is there any way to get 'x' rows using a computed value in the 'SELECT TOP' clause. I know of the 'rowcount' way but that doesnot solve the problem as I am making this query in XML.

Please HELP!

Regards,
Not a DBA yet
SQL Server 2005 allows you to specify variable in TOP clause (previous versions don't allow it). So you have to:
1. evaluate the number of rows and assign it to variable
2. run SELECT TOP (@YourVariable) ... from ...
May 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Craig Stadler | last post: by
6 posts views Thread by Elpetha Brooke | last post: by
2 posts views Thread by Eric | last post: by
2 posts views Thread by mfyahya | last post: by
4 posts views Thread by Nicolae Fieraru | last post: by
1 post views Thread by Aaron | last post: by
4 posts views Thread by Iwan Petrow | last post: by
2 posts views Thread by jw_guildford | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.