![]() DECLARE AS DATE = '' DECLARE AS DATE = '' - CurrentDate will be incremented each time through the loop below. Change if it's 2014 and you run across this script. ![]() This is the start and end date ranges to use to populate the - dbo.DimDate dimension. Create a month table to hold the months and their language versions. Create a table variable to hold the days of the week with their various language versions DECLARE TABLE Since everything is calculated, we'll just create this little bogus table to have something - to select from. I want to - join the day and month name memory variable tables, but need to have something to join to. PRINT 'Adding new dates to dbo.DimDate' GO SET NOCOUNT ON - Later we will be writing an INSERT INTO. Commented out for this project as future dates are OK - If the date is in the future, don't allow it, change to missing - IF > - SET = -1 RETURN GO + If there's any data prior to 2000 it was incorrectly entered, mark it as missing If the date is missing, or a placeholder for a missing date, set to the Id for missing dates Create a helper function to convert dates to a YYYYMMDD format Date Id. PRINT 'Done Creating AdventureWorksDW2014 ' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ DATA\AdventureWorksDW2014_log.ldf ', TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ DATA\AdventureWorksDW2014_Data.mdf ', PRINT 'Restoring AdventureWorksDW2012 to AdventureWorksDW2014 'įROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ Backup\AdventureWorksDW2012.bak ' PRINT 'Deleting AdventureWorksDW2014, if it exists 'ĮXEC _delete_database_backuphistory = N'AdventureWorksDW2014 ' Delete the database AdventureWorksDW2014 if it exists. NAME = N'AdventureWorksDW2012- Full Database Backup ', TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ Backup\AdventureWorksDW2012.bak ' * Step 1 - Make a copy of AdventureWorksDW2012 and restore as AdventureWorksDW2014 */ ![]() PRINT 'Updating AdventureWorks2012 for Today - Starting ' * Be warned, if AdventureWorksDW2014 exists, it will be deleted as part of this process. It won 't change AdventureWorksDW2012 in anyway. This script is dependent on the AdventureWorks2012DW sample */ It will then update it for current dates. * This script will make a backup of the AdventureWorks2012DW database, then copy and restore it */ * AdventureWorks database Copyright (c) Microsoft. * Script Copyright (c) 2013 by Robert C. * Updating AdventureWorks2012 for Today */ Copy and paste into SQL Server Management Studio and it should work fine. Note some browsers don’t seem to render the script using the mono-spaced font I intend, but just ignore. I’ve now updated the script for 2014, thought I’d pass along the updated version. This will allow folks to demo date related queries and be able to simply use things like GETDATE or NOW without having to do funky math tricks to take into account the pitifully out of date offering. ![]() A while back I did a post that contained a script to update the AdventureWorksDW2012 database to have dates for the 2013 time period.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |