Controlling DB View's return dataset using WHERE Clause?

  • There is a DB view (based on a big table which has say 100k rows+), which is accessible to end users via Excel or Visual Studio tools, after they have successfully made a connection to the corresponding Database within the same tools.

    Is there a way using which we can JUST show the initial 1000 rows of the view return dataset as an initial DEFAULT. And then if the user does a query on the view using WHERE clause then he sees the expected no of rows (could now be more than 1000).

    Basically, we want the landing screen (within the calling tools) to only show some 1000 rows at the first place instead of user to wait for couple of mins to see the whole data.

    I was wondering if the there is some way where by the "WHERE" clause can be used somehow to control that view's return dataset, meaning...

    1. On the first call, by default, the view will return say expected 1000 rows.

    2. But, then a user can pass "something" in the "where clause", which would NOW return their expected result by "somehow" ignoring/skipping the default 1000 rows condition.

    Please let me know if you could suggest any such special WHERE clause, specially incase you have come across such thing before!!. Thanks for your patience.

  • The view is defined when you use CREATE VIEW and anything you do in there will be in effect on any call. If the view is queried from either Excel or Visual Studio, there really is not a way to tell the View to only return so many rows on the first call. You can do this with a Stored Proc, but with a view it is meant to be a view into tables joined or whatever using a single entity.

    So there is a way to use SELECT TOP 1000 * from viewname if you have a template Excel spreadsheet and then they could tweak the query to have the right where clause and remove the select top 1000, but this is probably not what you are looking for, because it is just not how SQL Server works.



    Ben Miller
    Microsoft Certified Master: SQL Server, SQL MVP
    @DBAduck - http://dbaduck.com

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply