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 3942008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:36:41+00:00 2026-05-20T00:36:41+00:00

I have a 5 year data set partitioned into quarterly tables. I also have

  • 0

I have a 5 year data set partitioned into quarterly tables. I also have a master view that joins them all together. When a user needs more than one quarter of data they often use the master view instead of joining multiple quarters together.

My question is, would a table valued function which accepts a date range and returns only the records from the necessary partitions be faster than querying the entire master view?

This is my current view definition:

ALTER VIEW [dbo].[loandetails_test]
AS
SELECT     *
FROM         loandetails05
where year(date) = 2005
UNION
SELECT     *
FROM         loandetails06
where year(date) = 2006
UNION
SELECT     *
FROM         loandetails07
where year(date) = 2007
UNION
SELECT     *
FROM         loandetails08
where year(date) = 2008
UNION
SELECT     *
FROM         loandetails1q09
where date >= '1/1/2009' and date < '4/1/2009'
UNION
SELECT     *
FROM         loandetails2q09
where date >= '4/1/2009' and date < '7/1/2009'
UNION
SELECT     *
FROM         loandetails3q09
where date >= '7/1/2009' and date < '10/1/2009'
UNION
SELECT     *
FROM         loandetails4q09
where date >= '10/1/2009' and date < '1/1/2010'
UNION
SELECT     *
FROM         loandetails1q10
where date >= '1/1/2010' and date < '4/1/2010'
UNION
SELECT     *
FROM         loandetails2q10
where date >= '4/1/2010' and date < '7/1/2010'
UNION
SELECT     *
FROM         loandetails3q10
where date >= '7/1/2010' and date < '10/1/2010'
UNION
SELECT     *
FROM         loandetails4q10
where date >= '10/1/2010' and date < '1/1/2011'
union
SELECT     *
FROM         loandetails_CURRENT
where date >= '1/1/2011' and date < '4/1/2011'


GO
  • 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-05-20T00:36:42+00:00Added an answer on May 20, 2026 at 12:36 am

    The answer should be a solid no.

    Partitions are set up with implicit criteria, so if you are doing it by date (quarter), SQL Server already knows which partitions will satisfy the query (assuming the query will have a date filter). Check the execution plan which will confirm a stream-merge between two (or as many as involved) partitions.

    I have a case where tables from N databases (yes one per silo) are joined in a master view, like you have. The master view uses a filter for each one, specifically it looks like this

    select source=1, col1, col2, col3
    from db1.dbo.tbl
    union all
    select source=2, col1, col2, col3
    from db2.dbo.tbl
    etc
    

    Any query that asks for where source in (2,3) automatically recognizes that only 2 dbs need to be searched, and the execution plan reveals as much.

    If you manually created date-partitioned queries, you can

    1. have an index on the date range, within each table
    2. force the optimizer to recognize the partitioning

    Here is a working example (even without indexes). Notice that Q1 and Q4 are not even showing in the plan. Disclosure: SQL Server 2008 R2 Express

    select dateadd(d, number, '20100101') TheDate, *
    into Q1data
    from master..spt_values
    where type='p' and number between 1 and 370
    and datepart(quarter, dateadd(d, number, '20100101')) =1
    
    select dateadd(d, number, '20100101') TheDate, *
    into Q2data
    from master..spt_values
    where type='p' and number between 1 and 370
    and datepart(quarter, dateadd(d, number, '20100101')) =2
    
    select dateadd(d, number, '20100101') TheDate, *
    into Q3data
    from master..spt_values
    where type='p' and number between 1 and 370
    and datepart(quarter, dateadd(d, number, '20100101')) =3
    
    select dateadd(d, number, '20100101') TheDate, *
    into Q4data
    from master..spt_values
    where type='p' and number between 1 and 370
    and datepart(quarter, dateadd(d, number, '20100101')) =4
    GO
    
    create view Ydata
    with schemabinding
    as
    select TheDate, name, number, TYPE, LOW, high, status
    from dbo.Q1Data where TheDate >= '20100101' and TheDate < '20100401'
    union all
    select TheDate, name, number, TYPE, LOW, high, status
    from dbo.Q2Data where TheDate >= '20100401' and TheDate < '20100701'
    union all
    select TheDate, name, number, TYPE, LOW, high, status
    from dbo.Q3Data where TheDate >= '20100701' and TheDate < '20101001'
    union all
    select TheDate, name, number, TYPE, LOW, high, status
    from dbo.Q4Data where TheDate >= '20101001' and TheDate < '20110101'
    GO
    
    select * from YData where TheDate between '20100601' and '20100831'
    

    Query Plan

    enter image description here

    Re: Updated question

    When dealing with date ranges, NEVER (with few exceptions) use a function on the date column. This requires the function to be run against ALL records in the table before comparing to the other side.

    where year(date) = 2005
    ===> means scan the table, for each row take the year, compare to 2005
    

    Better to write as

    where date >= '20050101' and date < '20060101'
    ===> means given a date range, use the index to seek the range
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that includes cases by year and month. Some months
I have a data set that looks like the following: movie (year) genre for
Say you have a few DropDownLists that filter data: Car Make: [Ford,Chevrolet,etc] Car Year:
I have an unbalanced quarterly panel data set with missing values. I want to
I have a set of data that needs to be displayed as a crosstab
I am working with a set of data that I have converted to a
I have a Core Data project with a sort of master entity that holds
I have a data set that looks like this: ByYear <- data.frame( V1 =
I have a calendar table with data from year 2000 to 2012 (2012 wasn't
If I have the following: {hdrs: [Make,Model,Year], data : [ {Make:Honda,Model:Accord,Year:2008} {Make:Toyota,Model:Corolla,Year:2008} {Make:Honda,Model:Pilot,Year:2008}] }

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.