snippet

Careful with your LINQ joins (WHERE IN TSQL with LINQ)

So today I needed to cross reference some stuff in a text file with some stuff in a db. No big deal. Had about 200 unique values to lookup a few pieces of info out of a larger table in a db. The target table had about a half million rows in it, but was indexed on this particular column I needed to lookup on so it seemed like it should be no big deal. I have found myself using LINQPad more and more for little ad-hoc stuff like this. Anyway, I was prepared to do something similar to this:...

posted @ Tuesday, June 08, 2010 6:20 PM | Feedback (0)

stupid macro for adding some leading text in an outlook window

so since i have looked this up and figured it out (i know... there isn't much to figure it out, but there it is) i figured i should blog about it so i can quit looking it up somewhere else. basically i just needed to hit a button/hotkey int outlook and have it insert the time/date stamp and my name and a couple of pipes to just divide everything up. no biggy. but if you never create macros and do this once every two years, it's a bit of a pain to remember how. this is for outlook 2007, i think...

posted @ Wednesday, May 26, 2010 10:20 AM | Feedback (0)

how to graph / chart multiple ping results using shell scripting and logparser

i probably should have called this post 'stupid batch file tricks' or 'how much time do you want to waste on batch files' as well. =P anyway, i needed to graph something else, and i was fiddling around with logparser. if you have ever fiddled, you have probably googled, and if you have ever googled for logparser, you probably have come across Ken Schaefer's blog post about graphing ping results. it's at http://www.adopenstatic.com/cs/blogs/ken/archive/2005/05/30/22.aspx if you haven't. go check it out. i will wait. it's quite short. wayyyy shorter than this. =P anyway, i wanted to represent several test result series from...

posted @ Wednesday, May 26, 2010 1:00 AM | Feedback (0)

count lines with linq

so i needed to count the lines of a bunch of different filetypes in a folder. i decided to try using linq for this. here's what i came up with. basically a single linq statement =Pyou can tune the regex to taste. i just said (i think, i'm not a regex wizard) something that isn't a newline (.+) and the line terminators i'm using (\r\n). using System;using System.Collections;using System.IO;using System.Linq;using System.Text.RegularExpressions;namespace LineCounter{    class LineCounter    {        static void Main(string[] args)        {            // dir to search            string d = @"c:\pathtocode";            // regex match for newlines            string lf = @".+\r\n";                        // get the...

posted @ Wednesday, June 11, 2008 2:07 PM | Feedback (1)

directory list with a stack instead of recursion

Stack q = new Stack();q.Push(argument);while (q.Count > 0){    string d = q.Pop().ToString();    Console.WriteLine(d);    foreach (string sd in Directory.GetDirectories(d))        q.Push(sd);}

posted @ Tuesday, June 10, 2008 6:41 PM | Feedback (0)

how can i get some performance statistics on my stored procedures in sql2005?

select    case when dbid = 32767        then 'resource'        else db_name(dbid)    end [db_name]    , object_schema_name(objectid,dbid) [schema_name]    , object_name(objectid,dbid) [object_name]    , sum(usecounts) [executions]    , max(max_execution_time) [last_execution_time]    , sum(total_logical_reads) [total_logical_reads]    , sum(total_logical_reads) / sum(usecounts) * 1.0 [avg_logical_reads]    , sum(total_elapsed_time) / 1000 [total_elapsed_time_ms]    , ( sum(total_elapsed_time) / sum(usecounts) * 1.0 ) / 1000 [avg_elapsed_time_ms]from    sys.dm_exec_cached_plans cp    cross apply sys.dm_exec_sql_text(cp.plan_handle) qt    join (        select            plan_handle            , max(last_execution_time) [max_execution_time]            , sum(total_elapsed_time) [total_elapsed_time]            , sum(total_logical_reads) [total_logical_reads]        from            sys.dm_exec_query_stats        group by            plan_handle        ) r on r.plan_handle = cp.plan_handlewhere    objtype = 'Proc'   ...

posted @ Friday, March 21, 2008 8:57 PM | Feedback (0)

SQL Server 2005 Emergency Diagnostic and Performance Queries

Great useful base diag scripts! Snipped from http://glennberrysqlperformance.spaces.live.com/blog/cns!45041418ECCAA960!893.entry -- SQL Server 2005 Emergency Diagnostic and Performance Queries-- Glenn Berry 3-17-2008 -- Step 1 - Check Task Manager. Are all CPUs above 90-95% for an extended period of time?-- If yes, run HIGH CPU queries below:-- Step 2 - Check Performance Monitor-- SQL Server Buffer Manager: Buffer Cache Hit Ratio and Page Life Expectancy-- SQL Server Memory Manager: Memory Grants Pending and Memory Grants Pending-- Physical Disk: Avg disk sec/Read and Avg disk sec/Write-- Step 3 - Check for locking, blocking and missing indexes-- Run the...

posted @ Friday, March 21, 2008 7:19 PM | Feedback (0)

how can i find when a stored procedure was last executed in sql 2005?

select top 10    t.text    , s.last_execution_time    , *from    sys.dm_exec_query_stats s    cross apply sys.dm_exec_sql_text(s.sql_handle) twhere    t.objectid is not null    and text like '%procname%'order by    s.last_execution_time desc obviously replace procname with the procname you want to find. you might get multiple results, and you can probably clean it up some, but it works fine for what i generally need to get the info for. while i was researching this, i also came accross this pretty cool query: -- Get Top 200 executed SP's ordered by calls/minuteSELECT TOP 200 qt.text AS 'SP Name', qs.execution_count AS 'Execution Count', qs.total_worker_time/ISNULL(qs.execution_count, 1) AS 'AvgWorkerTime',qs.total_worker_time AS 'TotalWorkerTime',qs.total_elapsed_time/ISNULL(qs.execution_count, 1) AS...

posted @ Friday, March 21, 2008 6:22 PM | Feedback (0)

enable clr procs on sql2005

EXEC sp_configure    @configname = 'Show Advanced Options',    @configvalue = 1 RECONFIGURE WITH OVERRIDEGOEXEC sp_configure    @configname = 'clr enabled',    @configvalue = 1 RECONFIGURE WITH OVERRIDEGOEXEC sp_configure go

posted @ Wednesday, March 19, 2008 6:26 PM | Feedback (0)

multiple objects in a using and compression sample

Found something nifty I didn't know about today. create multiple objects in a single using statement. I figured i would include some sample code i use for compression/decompression. I'm using the #ziplib libraries, but you could use any stream based process really. The bufferSize variable you can change to fit your needs.    //unzip data. assume we have a compressed file and are creating the output file using (FileStream     u = File.Create(PathToUncompressedFile),     c = File.OpenRead(PathToCompressedFile)) using (GZipInputStream gzip = new GZipInputStream(c))     while ((bufferSize = gzip.Read(buffer, 0, buffer.Length)) != 0)         u.Write(buffer, 0, bufferSize);   //zip data. assume we have a uncompressed file and are creating the output file using (FileStream     u...

posted @ Saturday, March 08, 2008 1:52 AM | Feedback (0)

Full snippet Archive