SQLServerCentral - www.sqlservercentral.com

A community of more than 1,600,000 database professionals and growing

Featured Contents

Featured Script

The Voice of the DBA

Three Days and a Notebook

This is a short week of work for me, really just today before heading off to attend Microsoft Build 2017. I'll spend the rest of the week watching Microsoft show off their latest tools, ideas, technology, and more at the developer's conference. I'm not speaking (I think) and am looking forward to three days of learning, watching, and getting excited about building software that for the most part depends on data in some way. I'm not sure what will be presented, as the schedule hadn't been posted as of the time I wrote this, but I'm sure there will be plenty of Azure and SQL to go with all the Windows and .NET sessions. I'm especially interested in ways that DevOps is making its way into the Microsoft stack and looking forward to seeing the creative solutions out there.

I haven't attended Build since it was the PDC many years ago. It's been since the early 2000's when I went to a few of these events as a software developer. I first saw Microsoft showcase XML tools in the late 90s and tablets a few years later.  I always enjoyed these shows and after a few years off was looking forward to going back. Then they cancelled the event before it was reborn as Build. I've been trying to schedule a trip for the last 4 years, but scheduling keeps getting in the way. I know, it's a hard life, and I'm not complaining. It's been disappointing for me.

Last year I was actually offered the chance to go speak on behalf of Redgate at a session, and I did go, but with volleyball trips planned with my daughter, I was in San Francisco about 24 hours, saw 1/2 of the keynote and part of one session (besides my own) and then left. Not much of a Build event for me. I didn't even have time to go through the HoloLens line and give it a try. However, I had a few days with my daughter, so I can't complain at all.

This year I didn't have anything scheduled for May and got the chance to register early. I plan to try and leave my computer in the hotel room and work little. Instead, I'll walk around with my notebook, jot down ideas, and just think a bit about software, my career, and where Microsoft is going. This will be my thinking time for the week. Actually, I haven't had much thinking time this year, so I'm looking forward to the break.

I rarely attend any events or training without having some sort of commitment or responsibility these days. I try to fit in a few sessions or a pre-con here and there, but training time and focused time on something other than work is rare. For the first time in many years, I'll actually going as an attendee and doing the things many of you do at SQL Saturdays, SQL Bits, the Pass Summit, and other events. I'll be learning, focusing, racing from session to session, networking, and hopefully overdosing on new technology.

I'll try to summarize notes in a few blogs, and maybe even give a short recap as an editorial one day, but this should be a fun technology week for me.

Steve Jones from SQLServerCentral.com

Join the debate, and respond to today's editorial on the forums


The Voice of the DBA Podcast

Listen to the MP3 Audio ( 4.5MB) podcast or subscribe to the feed at iTunes and Libsyn. feed

The Voice of the DBA podcast features music by Everyday Jones. No relation, but I stumbled on to them and really like the music.

ADVERTISEMENT
Database DevOps

Database DevOps Demo Webinar

Learn how to automate your database deployments alongside your app code in this free demo webinar. Register now.

SQL Monitor

New SQL Monitor Reporting Module

SQL Monitor now includes a new Reporting module. It allows you to create customized reports, combining the individual server performance metrics available in SQL Monitor with summary information on your entire SQL Server estate. These reports can then be exported to pdf and emailed to you on a scheduled basis. Download SQL Monitor now and get a 14 day free trial.

Featured Contents

 

View R Plots from within SQL Server Management Studio

Bill Palace from SQLServerCentral.com

Describes how to view R plots in SSMS and gives a brief introduction to R plotting More »


 

Deploying Multiple SSIS Projects via PowerShell

Additional Articles from SimpleTalk

When there are several SSIS projects with packages in a SQL Server Database or Data Warehouse development, automated deployments as part of Continuous Integration can get tricky. Nat Sundar describes how he created a Deployment script that is intended to provision a Data Warehouse for System Integrated testing (SIT). More »


 

Basic data masking for development work using SQL Clone and SQL Data Generator

Additional Articles from Redgate

This article describes a lightweight copy-and-generate approach for making a sanitized version of a production database available to development teams with SQL Clone and SQL Data Generator. More »


 

From the SQLServerCentral Blogs - Why is a Windows authenticated login more secure than a SQL authenticated one?

Kenneth Fisher from SQLServerCentral Blogs

I had this question come up at work the other day and while I knew it was true I wasn’t... More »


 

From the SQLServerCentral Blogs - Query Hash Values, Plan Guides and the Query Store

Grant Fritchey from SQLServerCentral Blogs

I was eating dinner with Hugo Kornelis and we started talking about query hash values. You know, like everyone does... More »

Question of the Day

Today's Question (by Thomas Franz):

You create a simple In-Memory-Table:

 CREATE TABLE dbo.test (id TINYINT NOT NULL CONSTRAINT PK_test PRIMARY KEY NONCLUSTERED HASH (id) WITH (BUCKET_COUNT = 512), ) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_ONLY);

Which Index_ID will the following query return:

 SELECT * FROM sys.indexes AS i WHERE i.object_id = OBJECT_ID('dbo.test')

PS: when you want to test it, you need at least SQL 2014 Enterprise / Developer or any edition of SQL 2016 SP1 and have to add an In-Memory-Filegroup to your database.

Think you know the answer? Click here, and find out if you are right.


We keep track of your score to give you bragging rights against your peers.
This question is worth 1 point in this category: In-Memory.

We'd love to give you credit for your own question and answer.
To submit a QOTD, simply log in to the Contribution Center.

ADVERTISEMENT

Securing SQL Server: DBAs Defending the Database

Protect your data from attack by using SQL Server technologies to implement a defense-in-depth strategy, performing threat analysis, and encrypting sensitive data as a last line of defense against compromise. The multi-layered approach in this book helps ensure that a single breach doesn't lead to loss or compromise of your data that is confidential and important to the business. Get your copy from Amazon today.

Yesterday's Question of the Day

Yesterday's Question (by Robert Eder):

Waht is the result data type for the query below?

 SELECT CAST(3.1415927 AS decimal(38,10)) / CAST(10000 AS decimal(38,10)) Result;

Answer: decimal(38,6)

Explanation:

The data type for the result is not based on any of the values within the arithmetic operation.  It is only based on the data type(s).  The BOL provides a formula for determining the precision and scale for the result.

Based on the formula for determining the precision and scale, the result would be 59 for precision and 49 for scale.  However, precision is limited to 38.  In addition, when the precision maximum value is exceeded, the scale becomes 6.  This results in a result data type of decimal(38,6).

click here


» Discuss this question and answer on the forums

Featured Script

Date Dimension Script

Dave Bunch from SQLServerCentral.com

T-SQL script that creates a Date-Dimension and populates it for any date-range desired. Includes columns specific to auto-dealerships which can be re-purposed and/or omitted:

  • CurrentBusDay
  • SalesHoliday
  • SalesHolidayName
  • ServiceHoliday
  • ServiceHolidayName
  • TotSalesBusDay
  • TotServiceBusDay

Also includes DaylightSavings_flag column (code for which was hard to find).

Special Kudos to jhadden's  'Federal Holiday Function' post: https://www.sqlservercentral.com/Forums/1248417/Federal-Holiday-Function.

USE --<database-name>
GO
/****** DIM_DATE Create table section                                   ******/
SET ANSI_NULLS ON
GO
--DROP TABLE dbo.Dim_Date
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name= N'Dim_Date' AND XTYPE='U')
BEGIN
     CREATE TABLE dbo.Dim_Date
     (
        DateKey              INT NOT NULL
       ,DateValue            DATE NULL
       ,YearDayNumber        INT NULL
       ,QuarterDayNumber     INT NULL
       ,MonthDayNumber       INT NULL
       ,YearMonthNumber      INT NULL
       ,MonthDays            INT NULL
       ,YearQuarterNumber    INT NULL
       ,QuarterDays          INT NULL
       ,YearNumber           INT NULL
       ,PreviousYear         INT NULL
       ,PreviousQuarter      INT NULL
       ,PreviousMonth        INT NULL
       ,WeekDayNumber        INT NULL
       ,[DayName]            VARCHAR(10) NULL
       ,YearWeekNumber       INT NULL
       ,[MonthName]          VARCHAR(10) NULL
       ,YearMonth            VARCHAR(8) NULL
       ,WeekFirstDay         DATE NULL
       ,WeekLastDay          DATE NULL
       ,MonthFirstDay        DATE NULL
       ,MonthLastDay         DATE NULL
       ,QuarterFirstDay      DATE NULL
       ,QuarterLastDay       DATE NULL
       ,PrevMonthFirstDay    DATE NULL
       ,PrevMonthLastDay     DATE NULL
       ,NextMonthFirstDay    DATE NULL
       ,NextMonthLastDay     DATE NULL
       ,DaylightSavings_flag BIT NULL
       ,MonthDayOccurrence   BIGINT NULL
       ,CurrentBusDay        INT NULL
       ,SalesHoliday         INT NOT NULL
       ,SalesHolidayName     VARCHAR(16) NOT NULL
       ,ServiceHoliday       INT NOT NULL
       ,ServiceHolidayName   VARCHAR(16) NOT NULL
       ,TotSalesBusDay       INT NULL
       ,TotServiceBusDay     INT NULL
     )
     ON [PRIMARY]
     CREATE UNIQUE CLUSTERED INDEX CDX_01_Dim_Date
       ON dbo.Dim_Date ( DateKey ASC )
       WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF,
     ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
/****** Populate DIM_DATE: date-range between @StartDate & @CutoffDate  ******/
DECLARE @StartDate DATE  = '1990-01-01' -- Start-date
DECLARE @CutoffDate DATE = '2036-01-01' -- End-Date
IF(OBJECT_ID('tempdb..#Date_Dim') IS NOT NULL)
BEGIN
    DROP TABLE #Date_Dim
END
IF(OBJECT_ID('tempdb..#Date_Dim2') IS NOT NULL)
BEGIN
    DROP TABLE #Date_Dim2
END
IF(OBJECT_ID('tempdb..#DimDate') IS NOT NULL)
BEGIN
    DROP TABLE #DimDate
END
SELECT CAST(CONVERT(VARCHAR(8),DateTrunc,112) AS INT)                                                     AS "DateKey"
      ,DateTrunc                                                                                          AS "DateValue"
      ,DATEPART(dy, DateTrunc)                                                                            AS "YearDayNumber"
      ,DATEDIFF(dd,MIN(DateTrunc) OVER (PARTITION BY DATEPART(yy, DateTrunc), DATEPART(q, DateTrunc)),DateTrunc)+1 AS "QuarterDayNumber"
      ,DATEPART(d, DateTrunc)                                                                             AS "MonthDayNumber"
      ,DATEPART(m, DateTrunc)                                                                             AS "YearMonthNumber"
      ,DAY(EOMONTH(DateTrunc))                                                                            AS "MonthDays"
      ,DATEPART(q, DateTrunc)                                                                             AS "YearQuarterNumber"
      ,DATEDIFF(dd,MIN(DateTrunc) OVER (PARTITION BY DATEPART(yy, DateTrunc), DATEPART(q, DateTrunc))
                  ,MAX(DateTrunc) OVER (PARTITION BY DATEPART(yy, DateTrunc), DATEPART(q, DateTrunc)) )+1 AS "QuarterDays"
      ,DATEPART(yy, DateTrunc)                                                                            AS "YearNumber"
      ,DATEPART(yy, DateTrunc) - 1                                                                        AS "PreviousYear"
      ,DATEPART(qq, DATEADD(month, -3, DateTrunc))                                                        AS "PreviousQuarter"
      ,DATEPART(m, DATEADD(month, -1, DateTrunc))                                                         AS "PreviousMonth"
      ,DATEPART(dw, DateTrunc)                                                                            AS "WeekDayNumber"
      ,CAST(DATENAME(dw, DateTrunc) AS VARCHAR(10))                                                       AS "DayName"
      ,DATEPART(ww, DateTrunc)                                                                            AS "YearWeekNumber"
      ,CAST(DATENAME(m, DateTrunc) AS VARCHAR(10))                                                        AS "MonthName"
      ,CAST(CONVERT(VARCHAR(7),DateTrunc,20) AS VARCHAR(8))                                               AS "YearMonth"
      ,DATEADD(dd, -(DATEPART(dw, DateTrunc)-1), DateTrunc)                                               AS "WeekFirstDay"
      ,DATEADD(dd, 7-(DATEPART(dw, DateTrunc)), DateTrunc)                                                AS "WeekLastDay"
      ,DATEADD(d, 1, EOMONTH(DATEADD(m, -1, DateTrunc)))                                                  AS "MonthFirstDay"
      ,EOMONTH(DateTrunc)                                                                                 AS "MonthLastDay"
      ,MIN(DateTrunc) OVER (PARTITION BY DATEPART(yy, DateTrunc), DATEPART(q, DateTrunc))                 AS "QuarterFirstDay"
      ,MAX(DateTrunc) OVER (PARTITION BY DATEPART(yy, DateTrunc), DATEPART(q, DateTrunc))                 AS "QuarterLastDay"
      ,DATEADD(d, 1, EOMONTH(DATEADD(m, -2, DateTrunc)))                                                  AS "PrevMonthFirstDay"
      ,EOMONTH(DATEADD(m, -1, DateTrunc))                                                                 AS "PrevMonthLastDay"
      ,DATEADD(d, 1, EOMONTH(DateTrunc))                                                                  AS "NextMonthFirstDay"
      ,EOMONTH(DATEADD(m, 1, DateTrunc))                                                                  AS "NextMonthLastDay"
      ,CAST(CASE
         WHEN DateTrunc BETWEEN DATEADD(dd,7 + (6-(DATEDIFF(dd,0,DATEADD(mm,(YEAR(DateTrunc)-1900) * 12 + 2,0))%7)),DATEADD(mm,(YEAR(DateTrunc)-1900) * 12 + 2,0))
          AND DATEADD(dd, (6-(DATEDIFF(dd,0,DATEADD(mm,(YEAR(DateTrunc)-1900) * 12 + 10,0))%7)),DATEADD(mm,(YEAR(DateTrunc)-1900) * 12 + 10,0)) THEN 1
         ELSE 0
        END AS BIT)                                                                                       AS "DaylightSavings_flag"
      ,ROW_NUMBER () OVER (PARTITION BY CAST(CONVERT(VARCHAR(7),DateTrunc,20) AS VARCHAR(8))
                                       ,DATENAME(dw, DateTrunc)
                               ORDER BY DateTrunc)                                                        AS "MonthDayOccurrence"
  INTO #Date_Dim
  FROM (SELECT DateTrunc = DATEADD(DAY, rn - 1, @StartDate)
          FROM (SELECT TOP (DATEDIFF(DAY, @StartDate, @CutoffDate)) rn = ROW_NUMBER() OVER (ORDER BY s1.[object_id])
                  FROM sys.all_objects AS s1
                  CROSS JOIN sys.all_objects AS s2
                ORDER BY s1.[object_id]) AS x) AS y;
SELECT T1.DateKey
      ,T1.DateValue
      ,T1.YearDayNumber
      ,T1.QuarterDayNumber
      ,T1.MonthDayNumber
      ,T1.YearMonthNumber
      ,T1.MonthDays
      ,T1.YearQuarterNumber
      ,T1.QuarterDays
      ,T1.YearNumber
      ,T1.PreviousYear
      ,T1.PreviousQuarter
      ,T1.PreviousMonth
      ,T1.WeekDayNumber
      ,T1.[DayName]
      ,T1.YearWeekNumber
      ,T1.[MonthName]
      ,T1.YearMonth
      ,T1.WeekFirstDay
      ,T1.WeekLastDay
      ,T1.MonthFirstDay
      ,T1.MonthLastDay
      ,T1.QuarterFirstDay
      ,T1.QuarterLastDay
      ,T1.PrevMonthFirstDay
      ,T1.PrevMonthLastDay
      ,T1.NextMonthFirstDay
      ,T1.NextMonthLastDay
      ,T1.DaylightSavings_flag
      ,T1.MonthDayOccurrence
      ,CASE
         -- Closed Sundays
         WHEN T1.WeekDayNumber = 1 THEN 0
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN 0
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN 0
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN 0
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN 0
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN 0
         ELSE 1
        END                                                    AS "SalesBusDay"
      ,CASE
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN 1
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN 1
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN 1
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN 1
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN 1
         ELSE 0
        END                                                    AS "SalesHoliday"
      ,CASE
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN
           'New Year''s Day'
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN
           'Independence Day'
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN
           'Thanksgiving Day'
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN
           'Xmas Eve'
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN
           'Xmas Day'
         ELSE
           ''
        END                                                    AS "SalesHolidayName"
      ,CASE
         -- Closed Sundays
         WHEN T1.WeekDayNumber = 1 THEN 0
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN 0
         --   Falls on Sunday
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 2 AND T1.WeekDayNumber = 2) THEN 0
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN 0
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN 0
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN 0
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN 0
         --   Falls on Sunday
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 26 AND T1.WeekDayNumber = 2) THEN 0
         ELSE
           1
        END                                                    AS "ServiceBusDay"
      ,CASE
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN 1
         -- Falls on Sunday
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 2 AND T1.WeekDayNumber = 2) THEN 1
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN 1
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN 1
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN 1
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN 1
         -- Falls on Sunday
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 26 AND T1.WeekDayNumber = 2) THEN 1
         ELSE 0
        END                                                    AS "ServiceHoliday"
      ,CASE
         -- New Year's Day
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 1) THEN
           'New Year''s Day'
         --   Falls on Sunday
         WHEN (T1.YearMonthNumber = 1 AND T1.MonthDayNumber = 2 AND T1.WeekDayNumber = 2) THEN
           'New Year''s Day'
         -- Independence Day
         WHEN (T1.YearMonthNumber = 7 AND T1.MonthDayNumber = 4) THEN
           'Independence Day'
         -- Thanksgiving Day (4th Thursday of November)
         WHEN (T1.YearMonthNumber = 11 AND T1.MonthDayNumber BETWEEN 22 AND 28 AND T1.WeekDayNumber = 5) THEN
           'Thanksgiving Day'
         -- Xmas Eve (December 24th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 24) THEN
           'Xmas Eve'
         -- Xmas Day (December 25th)
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 25) THEN
           'Xmas Day'
         --   Falls on Sunday
         WHEN (T1.YearMonthNumber = 12 AND T1.MonthDayNumber = 26 AND T1.WeekDayNumber = 2) THEN
           'Xmas Day'
         ELSE
           ''
        END                                                    AS "ServiceHolidayName"
  INTO #Date_Dim2
  FROM #Date_Dim T1
 ORDER BY 1
SELECT T1.DateKey
      ,T1.DateValue
      ,T1.YearDayNumber
      ,T1.QuarterDayNumber
      ,T1.MonthDayNumber
      ,T1.YearMonthNumber
      ,T1.MonthDays
      ,T1.YearQuarterNumber
      ,T1.QuarterDays
      ,T1.YearNumber
      ,T1.PreviousYear
      ,T1.PreviousQuarter
      ,T1.PreviousMonth
      ,T1.WeekDayNumber
      ,T1.[DayName]
      ,T1.YearWeekNumber
      ,T1.[MonthName]
      ,T1.YearMonth
      ,T1.WeekFirstDay
      ,T1.WeekLastDay
      ,T1.MonthFirstDay
      ,T1.MonthLastDay
      ,T1.QuarterFirstDay
      ,T1.QuarterLastDay
      ,T1.PrevMonthFirstDay
      ,T1.PrevMonthLastDay
      ,T1.NextMonthFirstDay
      ,T1.NextMonthLastDay
      ,T1.DaylightSavings_flag
      ,T1.MonthDayOccurrence
      ,SUM(T1.SalesBusDay) OVER (PARTITION BY T1.YearMonth ORDER BY T1.DateValue) AS CurrentBusDay
--      ,T1.SalesBusDay
      ,T1.SalesHoliday
      ,T1.SalesHolidayName
--      ,T1.ServiceBusDay
      ,T1.ServiceHoliday
      ,T1.ServiceHolidayName
      ,T2.TotSalesBusDay
      ,T2.TotServiceBusDay
   INTO #DimDate
   FROM #Date_Dim2 T1
   INNER JOIN (SELECT YearMonthNumber
                     ,MonthDays
                     ,YearNumber
                     ,MonthName
                     ,YearMonth
                     ,SUM(SalesBusDay)   AS TotSalesBusDay
                     ,SUM(ServiceBusDay) AS TotServiceBusDay
                  FROM #Date_Dim2
               GROUP BY YearMonthNumber
                       ,MonthDays
                       ,YearNumber
                       ,MonthName
                       ,YearMonth) T2
    ON T2.YearMonth = T1.YearMonth
ORDER BY 1
USE --<database-name>
GO
INSERT INTO dbo.Dim_Date
           (DateKey
           ,DateValue
           ,YearDayNumber
           ,QuarterDayNumber
           ,MonthDayNumber
           ,YearMonthNumber
           ,MonthDays
           ,YearQuarterNumber
           ,QuarterDays
           ,YearNumber
           ,PreviousYear
           ,PreviousQuarter
           ,PreviousMonth
           ,WeekDayNumber
           ,[DayName]
           ,YearWeekNumber
           ,[MonthName]
           ,YearMonth
           ,WeekFirstDay
           ,WeekLastDay
           ,MonthFirstDay
           ,MonthLastDay
           ,QuarterFirstDay
           ,QuarterLastDay
           ,PrevMonthFirstDay
           ,PrevMonthLastDay
           ,NextMonthFirstDay
           ,NextMonthLastDay
           ,DaylightSavings_flag
           ,MonthDayOccurrence
           ,CurrentBusDay
           ,SalesHoliday
           ,SalesHolidayName
           ,ServiceHoliday
           ,ServiceHolidayName
           ,TotSalesBusDay
           ,TotServiceBusDay)
SELECT S.*
  FROM #DimDate S
  LEFT OUTER JOIN dbo.Dim_Date T (NOLOCK)
    ON T.DateKey = S.DateKey
 WHERE T.DateKey IS NULL
ORDER BY 1;

More »

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.

SQL Server 2016 : SQL Server 2016 - Administration

Upgrade Advisor Errors - I'm attempting to use the new Data Migration Assistant tool for the first time.  I've used the old upgrade advisor...

Identity in a table used previous number - Hi all, I have something that does not make sense to me. If anyone can give me clues that will be...


SQL Server 2016 : SQL Server 2016 - Development and T-SQL

Transpose dynamic rows into column - hello all, i would like to seek your kind help regarding the transpose of rows into columns. i have a table...

Choose the result NOT in a JOIN-query - I have this question selecting all students that are registered to a course. Select distinct Registrations.CourseId AS 'KursID', Course.CourseName AS...

Summarize field by week of the month - Hi Guys! Hope you can help me with this. I have 3 tables as: table 1 A        B             C1 1        1/1/17        10 2        1/7/17        20 3...


SQL Server 2014 : Administration - SQL Server 2014

Availability Group Listener - We have Always On with 3 nodes on that first 2 nodes are SQL Server cluster and 3rd node is...


SQL Server 2014 : Development - SQL Server 2014

(Quickly) Delete records from a table, with condition - Hello all, I'm supporting a database that I inherited so now having to handle some issues that are now arising.  In...


SQL Server 2012 : SQL Server 2012 - T-SQL

Insert new row into a table, but move the old row to an archive table. Trigger or SSIS? Table partitioning? - Hello, Basically the the subject line says it all.  I have been tasked with populating an empty table, but any subsequent...

records repeat based on condition in sql server - I have a question in SQL Server. Table : emp CREATE TABLE . (   NULL,   (50) NULL,   NULL,   ...

Extracting Episode Start and End Dates From Multiple Assignments - Hello, We have a Staff/Program Assignment that captures to whom and what program a particular patient is assigned.  It's a historical...

How to build a field name in a select statement - I'm about to build aselect statement as a string and execute it so I can create the column namesfrom text...

How can I see a DEPENDENCY TREE for objects used inside SP1 Stored Proc, and for each object referenced further inside each object, etc.? - ------------------------------------------------------------------------- -- NESTED DEPENDENCIES: -- the SQL below does not show all objects          -- (for example, if table is from other DB, it is...


Cloud Computing : SQL Azure - Administration

Cannot create a WebJob - Hello, I want to create WebJobs to replace my SQL agent jobs, I have read the following web site: https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-create-web-jobs


Reporting Services : SSRS 2012

Report Body Border not showing up in print out - I'd like to print the report with Report Body Border. How can I make it appear on my print out?...


Data Warehousing : Integration Services

Precedence constrains in a master package issue - I am running into an interesting problem with precedence constraints:  I have a set up with master package that executes 4...

Copy data from flat file with multiple headers - Hi, I am trying to copy data from a flat file (CSV) which has multiple headers between the row values to...

This email has been sent to newsletter@newslettercollector.com. To be removed from this list, please click here.
If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com.
This newsletter was sent to you because you signed up at SQLServerCentral.com.
Feel free to forward this to any colleagues that you think might be interested.
If you have received this email from a colleague, you can register to receive it here.
This transmission is ©2017 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
Contact: webmaster@sqlservercentral.com