This is just a placeholder for an article about BI / Data warehouse information. Just a snippet to talk about partitioned tables in SQL server to cover parallel execution and how to tailor that for speedier apps. Been working late every day now for the past 4 months trying to get this concept of a client dashboard ready for management review. Meeting with the head-honchos this week – hope to impress.
I do like the below snippet for use in SSIS to transform date/time to an int for my partitioned views and a date_dim table. Useful and used a lot.
declare @dt datetime
set @dt = GETDATE()
select cast(convert(char(8), @dt, 112) as int)
SSIS DateTime Tips/Tricks
yyyy-mm-dd
The common yyyy-mm-dd format is often used in file names, for example:
C:\Temp\ErrorCodes\2005-11-18.txt
A sample expression to achieve this is:
"C:\\Temp\\ErrorCodes\\" + (DT_WSTR,4)YEAR(GETDATE()) + "-"
+ RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + "-"
+ RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2) + ".txt"
A similar expression, but this time deriving the file name based on yesterday’s date, useful for loading the previous day’s data:
"C:\\Temp\\ErrorCodes\\" + (DT_WSTR,4)YEAR(DATEADD("dd", -1, GETDATE())) + "-"
+ RIGHT("0" + (DT_WSTR,2)MONTH(DATEADD("dd", -1, GETDATE())), 2) + "-"
+ RIGHT("0" + (DT_WSTR,2)DAY(DATEADD("dd", -1, GETDATE())), 2) + ".txt"
yyyymmdd
A simple yyyymmdd formatted string from a DateTime type variable
(DT_WSTR,4)YEAR(@[User::DateTimeVar])
+ RIGHT("0" + (DT_WSTR,2)MONTH(@[User::DateTimeVar]), 2)
+ RIGHT("0" + (DT_WSTR,2)DAY(@[User::DateTimeVar]), 2)
An alternative yyyymmdd formatted string from a DateTime type variable.
(DT_WSTR,8) (
(YEAR(@[User::DateTimeVar]) * 10000) +
(MONTH(@[User::DateTimeVar]) * 100) +
DAY(@[User::DateTimeVar])
)
An alternative yyyymmdd INT from a string variable or column in the format yyyy-mm-dd.
(DT_I4)(SUBSTRING(Date,1,4) + SUBSTRING(Date,6,2) + SUBSTRING(Date,9,2))
Calculate the Beginning of a Previous Month
This expression starts from today, moves back three months (as an example), subtracts the day-count from the current day-of-month to get the first day, then converts the expression to a DT_DBDATE type (which does not support a time component) then converts it back to a regular DT_DATE, which does have a time component – but now it’s truncated the time to 00:00 AM.
(DT_DATE)(DT_DBDATE)DATEADD("dd",-1 * (DAY(GETDATE())-1),DATEADD("month",-3,GETDATE()))
And for SQL I often get asked how to get the start of the current year, start of current month.
-- get start of year
SELECT DATEADD(year, DATEDIFF(year, 0, GETDATE()), 0)
-- get start of month
SELECT DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
-- end of month
SELECT DATEADD(mm, 1 + DATEDIFF(mm, 0, GETDATE()), 0) - 1
-- end of year
SELECT DATEADD(yy, 1 + DATEDIFF(yy, 0, GETDATE()), 0) - 1
Calculate the End of a Previous Month
To get Midnight on the last day of the previous month, we back up to the first day of the immediately following month, truncate the time to 00:00 (as in the previous example) and then subtract 1 minute to get the ending time of the previous day. (Note, in SQL Server 2005 SP2, subtracting 3ms to get the absolute last time-slice of the previous day did not work properly with the MONTH() function.)
DATEADD("mi",-1,(DT_DATE)(DT_DBDATE) DATEADD("dd",0,DATEADD("dd",-1 * (DAY(GETDATE())-1),DATEADD("month",-2,GETDATE()))))
Getting the Fiscal Year for a Date
To get the fiscal year for a given date, use the conditional operator to check the month part of the date, and return either the year part of the date, or the year part of the date plus one depending on the cutoff of the fiscal year definition. This sample assumes a fiscal year that ends June 30th:
MONTH( @[User::InputDate] ) <= 6 ? YEAR ( @[User::InputDate] ) : YEAR ( @[User::InputDate] ) + 1
Performance and Distribution / Scaling
Database Table Partitioning Tutorial – How to Horizontal Partition Database Table
http://blog.sqlauthority.com/2008/01/25/sql-server-2005-database-table-partitioning-tutorial-how-to-horizontal-partition-database-table/
http://sqlhero.wordpress.com/2009/06/13/partition-table-in-sql-server-2008/
http://msdn.microsoft.com/en-us/library/ms191174.aspx
Switching Partitions and Concurrency (Option 2 and Option 3)
ALTER TABLE … SWITCH … PARTITION is a very convenient way to move bulk data in and out of a partitioned table. However, the locking requirements of the ALTER TABLE statement might cause problems in situations when there are ongoing queries/DML on the table. Table 2 shows the summary of the current behavior:
http://technet.microsoft.com/en-us/library/cc966380.aspx
Data Warehouse Performance
Relational Data Warehouse or Reporting work loads are characterized by low volumes of very large transactions. These applications are often identified as having predominately read workloads (e.g. Decision Support, Analysis, and Reporting) with periodic feeds or batch loads. It is important to keep these characteristics in mind as we examine the significance of database design, resource utilization and system performance. The top performance bottlenecks or gotchas to avoid for Data Warehouse or Reporting applications are outlined below.
http://technet.microsoft.com/en-us/library/cc917690.aspx
Partitioned Tables, Parallelism & Performance considerations
Q: When querying SS2005 Partitioned Tables, what kind of parallelism should I expect to see and how will that affect performance?
http://blogs.msdn.com/sqlcat/archive/2005/11/30/498415.aspx