The new Table type allows you to save a table definition in the database which can be reused later to define table variables, stored procedure parameters and functions. To create a Type, we use the CREATE TYPE clause, for example: Examples Create Table-Type Variables DECLARE @t as dbo.ProductList; Creating a Stored Procedure with a Table-typed Parameter CREATE PROC dbo.uspGetOrdersforProduct ( Passing Table-parameters into Stored Procedures DECLARE @t as dbo.ProductList; EXEC dbo.uspGetOrdersforProduct @tCREATE TYPE dbo.ProductList as TABLE (
ProductName varchar(200) NULL,
ProductCategory varchar(200) NOT NULL)
Important Notes:
The metadata is visible using sys.table_types
Variables/parameters cannot be set to NULL – if no table is supplied, an empty table is generated
Not affected by transaction rollbacks
Do not cause recompilations
INSERT INTO @t VALUES
('Grey Slate Paver 10x10','Paver'),
('Blue Slate Paver 10x10','Paver'),
('Heritage Blue 12x6','Brick')
@t as dbo.ProductList READONLY,
@StartDate as Date,
@EndDate as Date
) AS
SELECT o.OrderId,
o.OrderDate,
o.CustomerId,
o.ProductId,
o.Amount,
o.Qty
FROM tOrder as o
INNER JOIN tProduct t on t.ProductId = o.ProductId
INNER JOIN @t as f on f.ProductCategory = t.ProductCategory and (t.ProductName is NULL or t.ProductName = f.ProductName)
WHERE o.OrderDate between @StartDate and @EndDate
INSERT INTO @t VALUES
(NULL,'Paver'),
(NULL,'Brick')
Tuesday, 28 October 2008
What’s New in SQL 2008 – Part 3 – Table Type
Posted by Kristen Hodges at 3:01 pm 0 comments
Labels: SQL
What’s New in SQL 2008 – Part 2 – Data Types
Date and Time Data Type Size (bytes) Example Notes Client Providers DATE 3 '2009-10-01' OLEDB: DBTYPE_DBDATE TIME 3-5 '13:12:00.1234567' Accurate to 100 nanoseconds OLEDB: DBTYPE_DBTIME DATETIME2 6-8 '2009-10-01 13:12:00.1234567' Accurate to 100 nanoseconds OLEDB: DBTYPE_DBTIMESTAMP DATETIMEOFFSET 8-10 '2009-10-01 13:12:00.1234567+02:00' Accurate to 100 nanoseconds OLEDB: DBTYPE_DBTIMESTAMP There are a number of new functions which can also be used with these new datatypes including: Other Data Type Size (bytes) Useage Returns Notes HIERARCHYID VARBINARY DECLARE @h hierarchyid = hierarchyid::GetRoot() DECLARE @c hierarchyid '/1/' Represents position in a hierarchy Actually a CLR function with several methods eg
ADO.Net: DateTime
ODBC: SQL_DATE
ADO.Net: TimeSpan
ODBC: SQL_TIME
Can specify precision ie decimal places eg DATETIME(3)
ADO.Net: DateTime
ODBC: SQL_TIMESTAMP
ADO.Net: DateTime
ODBC: SQL_TIMESTAMP
eg 5 bytes for 100k records at 6-LevelsSET @c = @h.GetDescendant(NULL, NULL)
SELECT @c.ToString()
Posted by Kristen Hodges at 2:52 pm 0 comments
Labels: SQL
What's New in SQL 2008 - Part 1 - Functionality
Function Usage Example Notes Declare & Initialise DECLARE @iValue as integer = 100; Compound Assignments SET @iValue -= 50 += -= *= /= %= Multi-Row Inserts Using VALUES INSERT INTO dimProduct (Label, BusinessKey,LastUpdatedBy,LastUpdatedDate) VALUES The insert is executed as a single transaction. MERGE MERGE INTO dbo.dimProduct as d INSERT (ProductName,ProductCategory) VALUES (s.ProductName, s.ProductCategory) WHEN NOT MATCHED BY SOURCE THEN DELETE Grouping Sets SELECT Year(OrderDate) as OrderYear, ()); () empty brackets represents an 'ALL' grouping Filtered Indexes CREATE NONCLUSTERED INDEX idxOrders_Product Change Data Capture Tracks data changes into a table.
UPDATE dimCustomer SET Balance += 200
('Grey Slate Paver 10x10',1111,'dbo','20091001 13:12:00'),
('Blue Slate Paver 10x10',1112,'dbo','20091001 13:12:00'),
('Black Slate Paver 10x10',1113,'dbo','20091001 13:12:00')
Interestingly, it can also be used like this:
SELECT * FROM (VALUES
('Grey Slate Paver 10x10',1111,'dbo','20091001 13:12:00')
('Blue Slate Paver 10x10',1112,'dbo','20091001 13:12:00')
('Black Slate Paver 10x10',1113,'dbo','20091001 13:12:00')
) as p (Label, BusinessKey,LastUpdatedBy,LastUpdatedDate)
USING dbo.dimProductStage as s ON d.ProductKey = s.ProductId
WHEN MATCHED THEN
UPDATE SET
d.ProductName = s.ProductName,
d.ProductCategory = s.ProductCategory
WHEN NOT MATCHED THEN
OUTPUT $action,
deleted.ProductId as DeletedId,
inserted.ProductId as InsertedId;
SalespersonId,
OrderType,
count(OrderId) as OrderCount,
sum(Amount) as OrderAmount
FROM factOrders
GROUP BY GROUPING SETS (
(OrderType, Year(OrderDate)),
(SalespersonId,OrderType, Year(OrderDate)),
(SalespersonId, Year(OrderDate)),
(Year(OrderDate)),
ON factOrders(OrderId,ProductId)
WHERE CreditFlag IS NULL
** to be discussed in further detail in an upcoming post **
Enabled using sys.sp_cdc_enable_db or sys.sp_cdc_enable_table
Disabled using sys.sp_cdc_disable_db or sys.sp_cdc_disable_table
Uses SQL Agent
Posted by Kristen Hodges at 2:50 pm 0 comments
Labels: SQL
SharePoint Magazine - Part 2 available now
My next article for SharePoint Magazine is available now.
http://sharepointmagazine.net/technical/administration/sell-sell-sell-why-build-a-dashboard-anyway-part-2-of-6
Posted by Kristen Hodges at 11:12 am 2 comments
Labels: Monitoring and Analysing, PerformancePoint, Sharepoint 2007 (MOSS)
Tuesday, 14 October 2008
PerformancePoint Planning: Error When Deleting Members of a Member Set
Unfortunately I discovered a problem in PPS Planning today which caused me a few headaches... thought I would pass it on to you!! The issue occurs when editing/creating a dimension member set... a save will fail if you do an outdent and a delete member immediately afterwards. Let me demonstrate. Let's presume you have a structure something like this: --- Expenses But you want to remove the Salaries level and end up with a structure that looks like this: --- Expenses If you do this: You will get an error when you save similar to the following: In order for it to work correctly, you MUST (in this order): I have logged this problem on Microsoft Connect. Please feel free to vote! https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=375153&SiteID=181
--- --- Salaries & Related
--- --- --- Salaries
--- --- --- --- Base Salary
--- --- --- --- Bonuses
--- --- --- --- Allowances
--- --- --- Tax Expense
--- --- Salaries & Related
--- --- --- Base Salary
--- --- --- Bonuses
--- --- --- Allowances
--- --- Tax Expense
Posted by Kristen Hodges at 12:14 pm 0 comments
Labels: Bug, PerformancePoint, Planning