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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:55:40+00:00 2026-05-19T23:55:40+00:00

I have a table that is partitioned by month (partmonth int). The stored proc

  • 0

I have a table that is partitioned by month (partmonth int). The stored proc used to query the table only receives a date range. I need to find a way to get all of the month numbers in the date range and pass them into a where in (1,2…) clause for the partitioned table. I have tried creating a temp table of the month numbers and using a where in (select monthnumber from #tmp), but this seems to execute the #tmp on each record or scan all partitions. I have also tried to join the partitioned table to the tmp table, but this seems to scan all partitions as well. I assume the query optimizer need hard values for the partmonth where.

query to get all month numbers:

declare @months varchar(100)

select d.* into #tmp
from
(select distinct MonthNumber from [date] where [date] between '1/1/2010' and '4/1/2010') d

select @months = coalesce(@months + ', ', '')  + cast(monthnumber as varchar(2)) from #tmp
select @months
drop table #tmp

Now I need to be able to use these month numbers in a select statement so that they trigger the correct partitions to be used.

Something like the following that does not work:
select * from [transactions]
where partmonth in (@months)

  • 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-19T23:55:40+00:00Added an answer on May 19, 2026 at 11:55 pm

    I have found using a select statment for “where in (…)” works for table partition filtering. The table scan I was seeing was due to other criteria used, i get the scan even if I pass in where in (10).

    I have also found that you can use the partition function for partition selection also, but in my environment and schema, it caused and index scan vs index seek.

    DECLARE @months TABLE (MonthNumber int)
    insert into @months
    select distinct MonthNumber from [date] where [date] between '10/1/2010' and '10/7/2010'
    
    select * from [transaction] t
    WHERE $Partition.TransactionPartitionFunction(t.partmonth) in (select monthnumber from @months) 
    

    Actual Execution plan resutls with set statistics xml on.
    Without where in:

    <RunTimePartitionSummary>
      <PartitionsAccessed PartitionCount="13">
        <PartitionRange Start="1" End="13" />
      </PartitionsAccessed>
    </RunTimePartitionSummary>
    

    With where in:

    <RunTimePartitionSummary>
      <PartitionsAccessed PartitionCount="1">
        <PartitionRange Start="10" End="10" />
      </PartitionsAccessed>
    </RunTimePartitionSummary>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that I insert data with following query (from c# code): INSERT
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have a table that looks like this: ID (pk,int) Col1 (nvarchar) Col2 (nvarchar)
I have a table that is partitioned by TRANSACTION_DATE_TIME. Table has a column: ID.
I have a partitioned table that belongs to tablespace report . I want to
I have a mysql database table that I want to partition by date, particularly
I have a table that contains multiple dropdown menus for a list of profile
I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have a table that acts as a dropbox for files that get automatically

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.