Search This Blog

Tuesday, February 26, 2013

SSIS 2012 Multi-column hash key transformation

Have you ever needed to do data comparisons over many columns and desire to use a hash key algorithm?  And needed to do it in SSIS?

I invite you to look at the information at CodePlex:

http://ssismhash.codeplex.com/documentation?referringTitle=Home


This is unbelievable stuff and it should be noted they're the authors of said code and documents.  Just thought it was great enough to share.

Thursday, February 21, 2013

How to pass a variable to an SSIS package on execute?

Q:  How to pass a variable to an SSIS package on execute?

A:  A few ways.  One can execute via a command line and designate the variable value, execute via SQL Agent and pass the value or use a config file.  I'm going to demo the 1st two below.

Execute via SQL Agent:



Or via command line:
*note: this example uses a SSIS package stored in a file folder.

/FILE "C:\SSIS\projects\SSIS_PKG.dtsx"  /CHECKPOINTING OFF /SET "\Package.Variables[User::myvar].Properties[Value]";myvalue /REPORTING E

Wednesday, February 6, 2013

SQL Server Database Backup Script

Looking for a quick database backup script with a datetimestamp?  Replace the [DBName] with your database name.  Note the [FolderPath] needs to be updated as well.

SQL Server Database Backup Script with datetimestamp:



--db name   [DBName]

--use master db for backups
use master

--variables
declare @year varchar(4)set @year=datepart(yy,getdate())
declare @month varchar(2)set @month=case when datepart(mm,getdate())<10 then '0'+cast(datepart(mm,getdate()) as varchar(1)) else cast(datepart(mm,getdate())as varchar) end
declare @day varchar(2)set @day=case when datepart(dd,getdate())<10 then '0'+cast(datepart(dd,getdate()) as varchar(1)) else cast(datepart(dd,getdate())as varchar) end
declare @hour varchar(2) set @hour=case when datepart(hh,getdate())<10 then '0'+cast(datepart(hh,getdate()) as varchar(1)) else cast(datepart(hh,getdate())as varchar) end
declare @minute varchar(2)set @minute=case when datepart(mi,getdate())<10 then '0'+cast(datepart(mi,getdate()) as varchar(1)) else cast(datepart(mi,getdate())as varchar) end

--create bkp device
declare @sqlscript varchar(2000)
set @sqlscript='exec sp_addumpdevice ''disk'', ''[DBName]_networkdevice'', ''[FolderPath]\[DBNAME]'+@year+''+@month+''+@day+''+@hour+''+@minute+'.BKP'''
exec (@sqlscript)

--bkp db
BACKUP DATABASE [DBName] TO [DBName_networkdevice] WITH  INIT ,  NOUNLOAD ,  RETAINDAYS = 5,  NAME = N'[DBName backup',  NOSKIP ,  STATS = 10,  DESCRIPTION = N'[DBName] backup',  NOFORMAT DECLARE @i INT
select @i = position from msdb..backupset where database_name='[DBName]'and type!='F' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name='[DBName]')
RESTORE VERIFYONLY FROM  [[DBName]_networkdevice]  WITH FILE = @i

--drop bkp device
exec sp_dropdevice '[DBName]_networkdevice'