Four SQL Tasks I do all the time (but commonly forget the
syntax)...
1. Converting dates to the YYYYMMDD format. I do this task constantly and recommend this naming convention for date dimension surrogate keys.. This example assumes DateSK will be the name of the Date Surrogate Key.
2. Remove or replacing a string with a blank (or something else). In this example, I will replace the instances of XYZ with nothing (which is the same as removing).
SELECT REPLACE (ColumnName,’XYZ’,’’)
3. Pull all the column names as well as Database Name, Table Name, and data type to prepare for data dictionaries when building data warehouses.
SELECT
TABLE_CATALOG as
[Database],
Table_name as [Table Name] ,
column_name as [Column Name],
DATA_TYPE as [Data Type]
FROM information_schema.columnsWHERE table_name = 'Resource_Table$ '
ORDER BY ordinal_position
SET IDENTITY_INSERT
Products ON
INSERT
into Products (ProductsSK, ProductName)
VALUES
(-1, 'Hammer')
SET IDENTITY_INSERT
Products OFF
Those are the four tasks I commonly use as but often forget the syntax.
No comments:
Post a Comment