Posts

Showing posts from 2013

How to benchmark my t-sql directly using dmv dm_exec_sessions

Tested on Sql Azure 11.0.9206.32 /* Get actual reads, writes and other nice to know stuff for benchmarking. Notice go statements which are crucial since stats seem to update by batch. */   go if   object_id ( 'tempdb..#stats' )   is   not   null   drop   table   #stats  select   getdate ( )   as   startTime , cpu_time , memory_usage , reads , writes , logical_reads , session_id   into   #stats   from   sys . dm_exec_sessions   a   where   session_id = @@spid go --do your magic stuff that need tuning go select      datediff ( ms , s2 . startTime , getdate ( ) )   as   ElapsedMs ,      s1 . cpu_time - s2 . cpu_time   as   cpu_time ,      s1 . memory_usage - s2 . memory_usage  ...

HierarchyId quick fun

--drop table dbo.Earth create   table   dbo . Earth    (      Id   hierarchyid   not   null ,      Path   as   Id . ToString ( ) ,      Data   varchar ( 500 ) ,      primary   key   clustered   ( id ) ) insert   dbo . Earth   ( id , data ) values    ( '/1/1/1/1/' , 'Monkey' ) ,    ( '/1/1/1/2/' , 'Horsey' ) ,    ( '/1/1/1/3/' , 'Piglet' ) ,    ( '/1/1/1/' , 'Mammal' ) ,    ( '/1/1/' , 'Animal' ) ,    ( '/1/1/2/' , 'Insect' ) ,    ( '/1/1/2/14/' , 'Ant' ) ,    ( '/1/2/' , 'Plant' ) ,    ( '/1/2/1/' , 'Tree' ) ,    ( '/1/2/1/1/' , 'Birch' ) ,    ( '/1/2/1/2/' , 'Oak' ) ,    ( '/1/' , 'Living stuff' ) ,    ( '/2/' , 'Moving stuff' ) ,    ( '/2/1/' , 'Cars' ) ,    ( ...

Zip all files in folder individually

This script will remove items after being zipped. Filename is appended .zip Create two files from code templates below then edit and execute zipfiles.cmd zipfiles.ps1 [CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string]$sourceFolderPath, [Parameter(Mandatory=$True,Position=2)] [string]$filePattern, [Parameter(Mandatory=$True,Position=3)] [string]$7zipExe ) $sourceFilePattern= $sourceFolderPath +"\" + $filepattern $files=get-childItem $sourceFilePattern $ErrorActionPreference = "Stop" if ($files) { foreach ($file in $files) { $zipFileName=$file.fullname+".zip" $programArgs = "a", "-tzip", $zipFileName , $file.fullname write-host $programArgs Invoke-Command -ScriptBlock { & $7zipExe $programArgs } remove-item $file } } zipfiles.cmd powershell -file .\zipfiles.ps1 "c:\FolderWithFiles\ManyTextFiles" "*.txt" "c:\progr...

Vital settings for Microsoft Office if you're a developer or technician

Microsoft Office (including Visio) is designed for novel writers. If you're a developer or technician, most "helpful" and "intelligent" features hinder or destroy your work.  Writing code examples, formulas or technical jargong is tedious. But can be easier if you follow these settings. General File / Options / Advanced / (smart cut and paste) Settings /  Uncheck "Adjust sentence and word spacing automatically" This prevents Office from inserting spaces in front of what you paste. The setting will also be used in Outlook even if there's no setting there. Disable auto-capitalize first character. (also for outlook) Prevents Office from destroying your code casing Options / Proofing / AutoCorrect options / AutoFormat as you type Uncheck "Straight Quotes" with "Smart Quotes" Uncheck Hyphens with dash This malforms any code pasted Excel Options / Advanced / Use system separators Change to . (per...

T-sql merge to partial target table by where-clause

/* Example of how to merge partial set of target table  In this example I merge from #mysource to #mytarget, but only affect type='car' */   if   object_id ( 'tempdb..#mytarget' )   is   not   null     drop   table   #mytarget if   object_id ( 'tempdb..#mysource' )   is   not   null     drop   table   #mysource create   table   #mytarget   (   id   int   not   null ,     type   varchar ( 100 )   not   null ,      name   varchar ( 100 )   not   null   ) create   table   #mysource   (   id   int   not   null ,     type   varchar ( 100 )   not   null ,      name   varchar ( 100 )   not   null ...

Aggregate field to comma separated text

--Works good with numbers, careful with text due to xml-conversion select stuff( ( select ','+AnimalId from dbo.Animal as a for xml path('') ), 1,1,'') AS AggregatedAnimalIdsAsString

Where did my measure go?

Image
In SSAS Tabular 2012, I created a measure from the aggregation button (sum) for a column, say Sales, and then the measure doesn't show up in the measuregrid. I can see the measure with the name Sum of Sales in the properties window. When I select it from here an empty cell is automatically selected. But I cannot see the formula nor delete the measure. If i browse the source code of the bim-file i see the measure here too. When I try creating a measure manually with the same name I get the error "An item with the same key has already been added" The reason was that I had a perspective selected that was not including the entire table I was working with. When using the quick-button (sum) for creating a measure, the measure isn't added to the perspective and therefore hidden. One may think that creating measures when using a perspective, they should be added to that perspective. And it actually does when writing the measure formula manually. It's just the...