tisdag 8 april 2014

SSAS tabular audit trace

Generating audit information from analysis services (SSAS) was just a setting on the olap database(multidimensional), but in tabular mode it doesn't seem to work.

The way to go as I understand is to use the ASTrace tool: https://sqlsrvanalysissrvcs.codeplex.com/

It's basically a sql profiler running as a service, saving the result to a database.

I good idea is to customize the trace template, otherwise you'll be flooded. Do this using SQL Profiler, create template, adjust the events you capture and export the template file. The QueryEnd event could be a start. Use the config file and restart the service.

måndag 28 oktober 2013

select max from multiple columns

I have a view reading from three tables: A, B and C. Each table has a Created timestamp. I want the view to show the latest timestamp in any of these three tables, to be able to find new rows since a certain date, even if it is just a new row in one of the tables.

I was about to do a case or a function, but found this little simple method.

This snippet returns 3 with column name of "value"
FROM ( VALUES (1), (2), (3) ) AS value(v)

Select Col1, Col2,
FROM ( VALUES (a.Created), (b.Created), (c.Created) ) AS value(v)
) as newDataCreated
From A
inner join B
on a.id = b.a_id
inner join C
on b.id = c.b_id

Works in SQL Server 2008 and newer versions.

onsdag 28 augusti 2013

Force prints to display

I you wan't to force print statements to display continuously when executing script in management studio, insert the following statement. SQL server do not treat severity 1-10 as an error, just a message.

RAISERROR ('Push the message!', 0, 1) WITH NOWAIT

torsdag 22 augusti 2013

T-SQl Query performance

Just some short notes on what to be aware of when experiencing bad performance.

  • Table Scans for sure, but also be aware of key-lookups. Those normally can be avoided be including the lookup column in the index. This is in my experience one of the more common opportunities to improve performance and not that obvious to spot.
  •  Table compression actually increases Query performance, but slows inserts down a bit. Generally if you have big tables, use table compression
  • If using a view as a source in a merge statement, you can save a lot of time by doing it in two steps, first store the result of the view in a temporary table and then do the merge with the temporary table as source.
  • A left join can in some cases be faster than an inner join. Strange but true.

måndag 1 oktober 2012

T-sql toggle bit data type

Even after ten years in sql-server world, you can still find something you didn't know..

I have a field in a table called IsTrue of the type bit. I just want to toggle it, if it's true, set to false and if it's false, set to true.

I was on my way to do a case statement when I realized there is at least to better ways of doing this.

the bitwise NOT operator way
update table set IsTrue = ~IsTrue

the bitwise  XOR operator way:
update table set IsTrue = IsTrue^1

found at:

Can't believe I didn't know you could do that in SQL Server... =)