To see all open handles, regardless of session, when using sp_xml_preparedocument use this command:
select * from sys.dm_exec_xml_handles(0)
http://msdn.microsoft.com/en-us/library/ms408299(v=sql.105).aspx
tisdag 3 juli 2012
måndag 18 juni 2012
Slow Oracle inserts from SSIS
Struggled for a while, with terrible performance when inserting a couple of millions of rows. Took about 4,5 hours using ole-db or ado.net with different drivers from both Oracle and others.
Tried the Attunity driver, and was stunned. 3,5 minutes instead of 4,5 hours.
Tried the Attunity driver, and was stunned. 3,5 minutes instead of 4,5 hours.
Maps with Ssrs
http://blogs.msdn.com/b/querysimon/archive/2012/06/17/bi-data-on-maps-in-sql-server-2012.aspx
Good post on maps with Reporting Services by Simon Lidberg, Microsoft.
One strong advantage using this technique, is that you can simplify the maps by removing parts of the world that are of no interest. Picture below is a reporting services 2008 r2 report.
Good post on maps with Reporting Services by Simon Lidberg, Microsoft.
One strong advantage using this technique, is that you can simplify the maps by removing parts of the world that are of no interest. Picture below is a reporting services 2008 r2 report.
torsdag 26 april 2012
T-SQL dynamic xml names
The scenario:
You want to import a xml file into SQL Server, but have one xml-file for developing and testing that is easy to read, and one for production that is using really short node names to minimize the size of the file.
The development file could look something like this:
<Root>
<Booking>
<BookingId>1</BookingId>
<BookingName>My own booking</BookingName>
<BookingRow>
<BookingRowId>1</BookingRowId>
</BookingRow>
</Booking>
</Root>
And the production file could look something like this:
<r>
<bo>
<boid>1</boid>
<bn>My own booking</bn>
<br>
<br>1</br>
</br>
</bo>
</r>
And you want to be able to use the same SQL-script to import the file, no matter wether is the production or development file. Try this then:
Declare @xmlfile xml
Declare @docHandle int
Declare @xmlPath varchar(50)
-- Step 1 - Set the base path based on something, filename, or have a startnode in the xml-file
if @fileName = 'C:\prodXmlFile.xml'
@xmlPath = '/r/bo'
else
@xmlPath = '/Root/Booking'
SELECT @xmlfile=InvoicesXML FROM (
SELECT * FROM OPENROWSET(BULK @FileName,
SINGLE_BLOB) AS Invoices ) AS Invoices(InvoicesXML)
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlfile
--begin try
SELECT * INTO Bookings
FROM OPENXML(@docHandle, @xmlPath,2)
WITH (
bookingId int 'bookingId | boid',
bookingName int 'bookingName | bn' )
-- This is the trick, an xpath expression the takes bookingId if it there, and boid if it is there
-- end try begin catch end catch
EXEC sp_xml_removedocument @docHandle
You want to import a xml file into SQL Server, but have one xml-file for developing and testing that is easy to read, and one for production that is using really short node names to minimize the size of the file.
The development file could look something like this:
<Root>
<Booking>
<BookingId>1</BookingId>
<BookingName>My own booking</BookingName>
<BookingRow>
<BookingRowId>1</BookingRowId>
</BookingRow>
</Booking>
</Root>
And the production file could look something like this:
<r>
<bo>
<boid>1</boid>
<bn>My own booking</bn>
<br>
<br>1</br>
</br>
</bo>
</r>
And you want to be able to use the same SQL-script to import the file, no matter wether is the production or development file. Try this then:
Declare @xmlfile xml
Declare @docHandle int
Declare @xmlPath varchar(50)
-- Step 1 - Set the base path based on something, filename, or have a startnode in the xml-file
if @fileName = 'C:\prodXmlFile.xml'
@xmlPath = '/r/bo'
else
@xmlPath = '/Root/Booking'
SELECT @xmlfile=InvoicesXML FROM (
SELECT * FROM OPENROWSET(BULK @FileName,
SINGLE_BLOB) AS Invoices ) AS Invoices(InvoicesXML)
EXEC sp_xml_preparedocument @docHandle OUTPUT, @xmlfile
--begin try
SELECT * INTO Bookings
FROM OPENXML(@docHandle, @xmlPath,2)
WITH (
bookingId int 'bookingId | boid',
bookingName int 'bookingName | bn' )
-- This is the trick, an xpath expression the takes bookingId if it there, and boid if it is there
-- end try begin catch end catch
EXEC sp_xml_removedocument @docHandle
måndag 26 mars 2012
Relational database clean
Sometimes when developing you want to start over with a clean database. But if you have relational integrity, and using the Identity feature in SQL server, it could be a bit tricky.
However, this does it for you:
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 1)'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
However, this does it for you:
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 1)'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
tisdag 20 mars 2012
T-SQL Split function
Split function to find the Nth word in a string
--select dbo.Split('abc,def', ',',2) --returns def
Create FUNCTION [dbo].[Split] (@fullString varchar(200), @separator char(1),@wordNo tinyint)
RETURNS VARCHAR(200) -- return_data_type.
AS BEGIN
declare @wordPart varchar(200),
@sepPos int=0,
@wordCount int = 1
while @wordCount <= @wordNo
begin
if @fullString = ''
return null
set @sepPos = CHARINDEX(@separator, @fullString, @sepPos) if @sepPos = 0set @sepPos = len(@fullString)
set @wordPart = SUBSTRING(@fullString, 1, @sepPos)set @fullString = REPLACE(@fullString, @wordPart,'')
set @wordCount = @wordCount +1
end
RETURN replace(@wordPart,',','')
END
--select dbo.Split('abc,def', ',',2) --returns def
Create FUNCTION [dbo].[Split] (@fullString varchar(200), @separator char(1),@wordNo tinyint)
RETURNS VARCHAR(200) -- return_data_type.
AS BEGIN
declare @wordPart varchar(200),
@sepPos int=0,
@wordCount int = 1
while @wordCount <= @wordNo
begin
if @fullString = ''
return null
set @sepPos = CHARINDEX(@separator, @fullString, @sepPos) if @sepPos = 0set @sepPos = len(@fullString)
set @wordPart = SUBSTRING(@fullString, 1, @sepPos)set @fullString = REPLACE(@fullString, @wordPart,'')
set @wordCount = @wordCount +1
end
RETURN replace(@wordPart,',','')
END
tisdag 13 mars 2012
Branding SSRS, and make it look like an Intranet
If you want to enhance the user experience and feeling of a group of Reporting Services reports and don't have SharePoint? You don't have to use the standard report library. Below is a screenshot where I use a tabular navigation looking a lot like a web site using just SSRS 2008 R2 standalone. The tabs are just actions that points to another report using the same header subreport. The user can navigate within the reports without having to go the the report library.
You could also brand use the web service interface to find reports and create your own branded SSRS portal using a SSRS report.
Prenumerera på:
Inlägg (Atom)


