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

  • Home
  • SEARCH
  • 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 7766989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:33:47+00:00 2026-06-01T15:33:47+00:00

In Scaling Up Your Data Warehouse with SQL Server 2008 R2 , the author

  • 0

In Scaling Up Your Data Warehouse with SQL Server 2008 R2, the author recommends using an integer date key in the format of YYYYMMDD as a clustered index on your fact tables to help optimize query speed.

What is the best way to convert your key date field to the Date Key? I feel the following would work, but is a bit sloppy:

select Replace(CONVERT(varchar,GETDATE(),102),'.','')

Clearly, I’m not using getdate, but rather a date column in the table that will be using in my aggregations.

First, how would you suggest making this conversion? Is my idea acceptable?

Second, has anyone had much success using the Date Key as a clustered index?

  • 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-01T15:33:48+00:00Added an answer on June 1, 2026 at 3:33 pm

    ISO long (112) would do the trick:

    SELECT CONVERT(INT, CONVERT(VARCHAR(8), GETDATE(), 112))
    

    Casting getdate() straight to int with ISO 112 gives 41008 for some reason, but going via a VARCHAR seems to work – i’ll update if i think of a faster cast.

    EDIT: In regards to the int only vs varchar debate, here are my findings (repeatable on my test rig & production server) Varchar method uses less cpu time for half a million casts but a fraction slower overall – negligible unless your dealing with billions of rows

    EDIT 2: Revised test case to clear cache and differnt dates

    DBCC FREEPROCCACHE;
    DBCC DROPCLEANBUFFERS;
    SET STATISTICS TIME ON;
    WITH    RawDates ( [Date] )
              AS ( SELECT TOP 500000
                            DATEADD(DAY, N, GETDATE())
                   FROM     TALLY
                 )
        SELECT  YEAR([Date]) * 10000 + MONTH([Date]) * 100 + DAY([Date])
        FROM    RawDates
    SET STATISTICS TIME OFF 
    
    (500000 row(s) affected)
    
     SQL Server Execution Times:
       CPU time = 218 ms,  elapsed time = 255ms.    
    DBCC FREEPROCCACHE;
    DBCC DROPCLEANBUFFERS;
    SET STATISTICS TIME ON;
    WITH    RawDates ( [Date] )
              AS ( SELECT TOP 500000
                            DATEADD(DAY, N, GETDATE())
                   FROM     TALLY
                 )
        SELECT  CONVERT(INT, CONVERT(VARCHAR(8), [Date], 112))
        FROM    RawDates
    SET STATISTICS TIME OFF 
    
    (500000 row(s) affected)
    
     SQL Server Execution Times:
       CPU time = 266 ms,  elapsed time = 602ms
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone had any experience scaling out SQL Server in a multi reader single
Using a scaling transform to negate the y-coordinate alters some conventions in Quartz drawing
I have a scaling problem with XYChart plotting: my data serie ranges in float
Using EC2 instances (along with Amazon Auto Scaling and Elastic Load Balancing) I have
A web-bot crawling your site and using bandwdith resources. Bots are numerous and for
I am doing some image scaling using GDI+ (C#), and have noticed a problem
Does scaling the image using: image=[UIImage imageWithCGImage:[image CGImage] scale:2.0 orientation:UIImageOrientationUp]; reduces the image quality?
I'm trying to implement image scaling in OpenGL using only glTexCoord2f() and glVertex2f() .
I'm scaling onstage MovieClips via AS properties scaleX or scaleY, which kills any kind
Can somebody share an experience concerning scaling vertically the ActiveMQ? I'm particularly interested how

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.