Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:39:24+00:00 2026-06-13T06:39:24+00:00

We have the following code: select * from View1 where (Timestamp >= @x) and

  • 0

We have the following code:

select * from View1 where (Timestamp >= @x) and (SomeCode like 'ABC%')

It runs terribly slow. But the code

select * from View1 where (Timestamp >= @x)      (*)

runs pretty fast. Also SomeCode like... filter runs pretty fast on the previous (*) code. So, it’s fast when two-phased. (View1 is a CLR computed view.)

Question: how to advice SQL Server 2008 R2 to make the query (more precisely, the two filters) in two phases, that is, first the Timestamp filter and then the SomeCode filter.

Note: Nesting the queries doesn’t work for us, it’s slow as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:39:25+00:00Added an answer on June 13, 2026 at 6:39 am

    There are probably better ways, but this one works for me:

    SELECT * from (SELECT * FROM View1 WHERE Timestamp >= @x) x
    WHERE field_x LIKE 'ABC%'
    

    This forces the fast query to be run first.

    Responding to the comments:

    Maybe “force” isn’t the right word, but I’ve definitely observed it making a difference. I’ll revise this if someone has a better suggestion.

    Responding to your comment:

    “Doesn’t work” = still slow?

    In which case: is the Timestamp column indexed? Is SQL Server running short on resources (memory, disk space) with the larger query? Have you looked at the execution plan?

    What happens if you really force the issue:

    SELECT * into #tmp FROM View1 WHERE Timestamp >= @x
    SELECT * from #tmp WHERE field_x LIKE 'ABC%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: function isValidAuthor($authorID){ $query = SELECT * FROM jos_users WHERE
I Have following code with LINQ var q = (from web in DataContext.Webs select
I have the following code $result = $handle->select()->from('store_details') ->where('store_details.store_id=?', $id) ->columns('store_details.store_name'); //->query(ZEND_DB::FETCH_OBJ); However, when
I have the following code in IndexController.php: $sql = 'SELECT * FROM ?'; $stmt
I have following code var res = from c in model.Data select new object[]
I have the following code: var searcher = new ManagementObjectSearcher(SELECT Name, Path FROM Win32_share);
I have the following code CSS select.select { color:#FFFFFF; height: 15px; width: 105px; background:#996633
I have the following mySQL code: SELECT c.categoryId, c.categoryName, c.categoryParent, c.categoryDescription, COUNT(p.productid) as totalProdsInCategory
I have following code return (EseshEntities.Current.Users.Select(u => new { Comunity = u.Apartment.Building.District.City })).ToList(); if
I have the following code that prompts the user to select a range of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.