Skip to content

Instantly share code, notes, and snippets.

View billinkc's full-sized avatar
💭
Presenting at #SQLSatOC

Bill Fellows billinkc

💭
Presenting at #SQLSatOC
  • Sterling Data Consulting
  • Kansas City, MO
View GitHub Profile
@billinkc
billinkc / PartitionedView.sql
Last active August 29, 2015 14:18
Demonstrates partitioned views
CREATE TABLE
dbo.MonthlyAllocationNonTransmitted
(
MonthlyAllocationId int NOT NULL,
[IsTransmitted] [bit] NOT NULL
CONSTRAINT [DF_MonthlyAllocationNonTransmitted_IsTransmitted] DEFAULT (CAST(0 AS bit)),
CONSTRAINT CK_MonthlyAllocationNonTransmitted_IsTrasmitted CHECK(IsTransmitted = CAST(0 AS bit)),
CONSTRAINT [PK__AccountingMonthlyAllocationNonTransmittedId1] PRIMARY KEY CLUSTERED
(
[MonthlyAllocationId] ASC
@billinkc
billinkc / ErrorCode.biml
Created March 25, 2015 15:20
Not biml specific, although there is a difference in the engine for emitting SSIS between 1.6 and 1.7 1.6 will generate the package while 1.7 will error out with Error 0 : Component OLE_SRC dbo_ErrorCodes of type AstOleDbSourceNode in Dataflow DFT Test has duplicate column reference with name 'ErrorCode' on ouput 'Error'. This may be due to the …
<!--
USE [tempdb]
GO
CREATE TABLE [dbo].[ErrorCodes]
(
[ErrorCodeId] [uniqueidentifier] NOT NULL
, [ErrorCode] [nvarchar](3) NOT NULL
, [ErrorText] [nvarchar](50) NOT NULL
, [CreateDate] [datetime] NOT NULL
@billinkc
billinkc / v_4495.biml
Created February 25, 2015 23:01
Does this break for 2012/2014 package emission?
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="CM_OLE" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;" />
</Connections>
<Packages>
<Package ConstraintMode="Linear" Name="v_4495">
<Variables>
<Variable DataType="Int32" Name="ExecSQLResult">0</Variable>
<Variable DataType="Int32" Name="NumOfJobsToRun">-1</Variable>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<FlatFileConnection FilePath="C:\ssisdata\at.txt" FileFormat="FFFAT" Name="CM_FF"></FlatFileConnection>
</Connections>
<FileFormats>
<FlatFileFormat Name="FFFAT" IsUnicode="false" ColumnNamesInFirstDataRow="true">
<Columns>
<Column Name="MyField" DataType="AnsiString" Length="15" Delimiter="CRLF"/>
</Columns>
</FlatFileFormat>
@billinkc
billinkc / FileRename.biml
Created January 9, 2015 17:20
SSIS File Archiving Expressions. See also http://i.stack.imgur.com/jcrTx.png
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package ConstraintMode="Linear" Name="ArchivePackagePattern">
<Variables>
<Variable DataType="String" Name="CurrentFileName">C:\ssisdata\SourceFile.txt</Variable>
<Variable DataType="String" Name="DateString" EvaluateAsExpression="true">(DT_WSTR, 4) YEAR(@[System::StartTime]) + "-" + RIGHT("0" + (DT_WSTR, 2) MONTH(@[System::StartTime]), 2) + "-" + RIGHT("0" + (DT_WSTR, 2) DAY(@[System::StartTime]), 2)</Variable>
<Variable DataType="String" Name="CurrentFileNameExtension" EvaluateAsExpression="true">RIGHT(@[User::CurrentFileName], FINDSTRING(REVERSE(@[User::CurrentFileName]), ".", 1 ))</Variable>
<Variable DataType="String" Name="ArchiveFileName" EvaluateAsExpression="true">REPLACE( @[User::CurrentFileName], @[User::CurrentFileNameExtension], "." + @[User::DateString] + @[User::CurrentFileNameExtension])</Variable>
</Variables>
</Package>
@billinkc
billinkc / GetOleDataWithParameter.biml
Created December 9, 2014 18:05
Sample Biml to demonstrate pulling data from one table and using it as a filter for a data flow.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="Source" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI10.1;Integrated Security=SSPI;" />
<OleDbConnection Name="Target" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI10.1;Integrated Security=SSPI;" />
<OleDbConnection Name="Reference" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI10.1;Integrated Security=SSPI;" />
</Connections>
<Packages>
<Package ConstraintMode="Linear" Name="GetData">
<Annotations>
<Annotation AnnotationType="Description">This package will pull only new data based on external observer table</Annotation>
@billinkc
billinkc / ColumnEnumerator.biml
Created November 26, 2014 20:21
Attempt to enumerate the columns in a data flow and failing spectacularly.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection ConnectionString="Provider=SQLNCLI10.1;Data Source=localhost\dev2014;Integrated Security=SSPI;Initial Catalog=tempdb" Name="CM_OLE_DB"></OleDbConnection>
</Connections>
<Packages>
<Package Name="POC" ConstraintMode="Linear">
<Tasks>
<Dataflow Name="DFT POC">
<Transformations>
<OleDbSource Name="OLE_SRC Get all columns" ConnectionName="CM_OLE_DB">
@billinkc
billinkc / Elementary cursor
Created November 18, 2014 19:27
Q&D cursor sample
DECLARE test_cursor CURSOR
READ_ONLY
FOR SELECT TOP 10
SV.name
FROM
master.dbo.spt_values AS SV;
DECLARE @name nvarchar(35)
OPEN test_cursor
@billinkc
billinkc / BeMoreClever
Created October 28, 2014 17:24
My brain isn't working. Should be a better way of writing these queries, possibly with some/any but I'm not seeing it
-- backfilled TreatySK values
CREATE TABLE #T
(
ClaimSK int NOT NULL
, TreatySK int NULL
, Scenario varchar(50)
);
INSERT INTO #T
@billinkc
billinkc / TranTest.cs
Created October 16, 2014 21:22
Tran test
static void Main(string[] args)
{
string connectionString = @"Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLOLEDB;Integrated Security=SSPI;Auto Translate=false;";
string queryTableMake = @"CREATE TABLE dbo.POC(i int IDENTITY(1,10) NOT NULL, txt varchar(30) NULL);";
string queryTranCheck = "SELECT @@trancount AS tc;";
string query = "INSERT INTO dbo.POC(txt) SELECT 'x'; SELECT SCOPE_IDENTITY() AS x;";
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();