473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2241
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

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

Similar topics

1
by: Craig Stadler | last post by:
Can someone help with query syntax regarding IN/EXISTS.. I'm trying to do this: insert into table2 (field1) select field1 from table1 where field1 not in (select field1 from table2) delete...
6
by: Elpetha Brooke | last post by:
Hi I have two tables TABLE1 t1_id int not null t1_other stuff blah blah TABLE2 t2_id int not null
2
by: Eric | last post by:
please help to select these rows from these tables my tables are table1 table1Id groupId table2id price 1 1 1 10 2 1 3 1000 3 1 ...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
1
by: Alex | last post by:
Hello I need to select records from table1 where column1 is a part of column2 in table2, but with this query I can't obtain the desired result: SELECT * from table1 a, table2 b where b.column2...
3
by: gajaya1 | last post by:
I tried similar to sql server to get first 100 rows using "Select top 100 from table1" does not work? Is there another syntax?
4
by: Nicolae Fieraru | last post by:
Hi All, I have a Table1 with ID, Name, Address, Purchase. I want to build a query which shows all the records from Table1 (only fields ID, Name, Address), but there shouldn't be listed records...
1
by: Aaron | last post by:
Sorry for the re-post, my original post wasn't very clear. this is very important. I need a query that can return wildcard matches if there's no exact match. I'm using IIS 5 with ASP.NET and MS...
4
by: Iwan Petrow | last post by:
Hi, I have a store procedure like this: CREATE PROCEDURE AAA @p1 int @p2 datetime @id int OUTPUT AS
2
by: jw_guildford | last post by:
My SQL Server has kicked out a deadlocked process, which should only be running a select statement, though there is another select on one of the tables in the WHERE clause (see code below). Can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.