-
Common Table Expressions (CTE) in SQL Server 2005 and Up
Thanks to the team at TechRepublic.com and BOL, I have used CTEs to delete duplicates with ease in SQL Server 2005 and higher. Learn more about CTEs at TechRepublic. Here meat of the article a sample: ;WITH SalesCTE(Product, SaleDate, SalePrice, Ranking) AS (SELECT Product , SaleDate , SalePrice , Ranking = DENSE_RANK() OVER(PARTITION BY Product,…
-
Using ActiveX to check the age of a file in SQL Server
Now, you can use ActiveX to check the age of a file before proceeding. The code assumes that you have already assigned the file location elsewhere in the DTS Package
-
Using ActiveX to Dynamically set a Variable in an SQL Server DTS Package
From time to time, you will need to dynamically set a variable in the middle of your DTS packages. The following code shows you how easy it is to build a variable dynamically. The variable will be filename which contains the current timestamp. Here is the code: ‘************************* ‘ Sets the file name to the…
-
Using NOCOUNT, ANSI Warnings and Temp Tables in SQL Server
Here are a few useful code fragments that I use all the time. You see too many Rows Affected Messages. First, NOCOUNT. If you don’t want SQL Server to return the Row Count (20 row(s) affected) after you execute a query, here is the code: — Turn off the rows affected message SET NOCOUNT ON…
-
Change a Date Format Using ActiveX and SQL DTS Transformations
Let’s say you are importing data from a flat file to SQL Server via DTS. Now, let’s say the date format in the source file is similar to this: YYYYMMDD. If your destination column is a datetime or smalldatetime, SQL server isn’t going to know what to do with this data, at least not initially.…
-
Adding Foreign Keys after a table is created in SQL Server
Well, you knew exactly what you needed when you created a table. Only now when you created a child table, the child table does not update with the information from your main table. Or worse you deleted something from your primary table and it still lives in the child table. You need a foreign key,…
-
Adding Checks after a table is created in SQL Server
Did you create a table, only to find that you need to add a check constraint? I created a quick example of how to add a check constraint after the table exists. In this example, we want to know if our user is alive or dead. 1 = alive, 0 = dead. Here is the…