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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MakingDBA
    New Member
    • May 2007
    • 3

    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
  • almaz
    Recognized Expert New Member
    • Dec 2006
    • 168

    #2
    Originally posted by MakingDBA
    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 ...

    Comment

    Working...