Friday, March 13, 2009

Derived Column Expression

I'm building an SSIS package and I want to create a derived column with hard coded value. The column is a bit type and I want to set the default value as "0".

In SSIS, I click the Derived Column component, and right click > Edit

Name the colum somthing.
Select 'add as new column>' for the second option
The expression is (DT_l1)"0"

The type will fill automatically, or you might need to set it yourself. You can leave everything else blank.

Wednesday, March 11, 2009

Truncate Table and Verify Truncate

SELECT COUNT(*) AS BeforeTruncateCount
FROM DBO.MyTable

TRUNCATE TABLE DBO.MyTable

SELECT COUNT(*) AS AfterTruncateCount
FROM DBO.MyTable

Thursday, March 5, 2009

Alter data type on a column

Since people keep asking me, here's how to force a change of datatype on a column even though SQL won't let you do this in Designer:

ALTER TABLE dbo.MyTable
ALTER COLUMN MyColulmn nvarchar(255)null

works on 2005 and 2008