<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-AU">
    <title>.NET Playground</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/dotNETPlayground/Atom.aspx" />
    <subtitle type="html">unearthing the fun in .net and sql server</subtitle>
    <id>http://geekswithblogs.net/dotNETPlayground/Default.aspx</id>
    <author>
        <name>Andrew den Hertog</name>
        <uri>http://geekswithblogs.net/dotNETPlayground/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2008-09-03T12:26:26Z</updated>
    <entry>
        <title>Google Chrome - Pros &amp; Cons</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/09/03/124876.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/09/03/124876.aspx</id>
        <published>2008-09-03T12:26:2610:00:00</published>
        <updated>2008-09-03T12:26:26Z</updated>
        <content type="html">&lt;p&gt;&lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt;, Safari, iExplorer, Firefox, and now Chrome. Like we didn't have enough mainstream browsers as it was. Google's attempt to grab a slice of yet another market has now been realised, but is their new Chrome offereing enough to get people to switch?&lt;/p&gt;
&lt;p&gt;I've finally had time to put Chrome through its paces on some of the sites I've created &amp;amp; maintained, which are all ajax-based, css standardised, and javascript heavy. As a devout &lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt; 10 user, it's next to impossible to get me to switch browsers, but will Chrome have enough shine to move me? &lt;/p&gt;
&lt;p&gt;To summarise:&lt;/p&gt;
&lt;p&gt;Pros&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Compiled Javascript - all the sites performed much faster&lt;/li&gt;
    &lt;li&gt;Site sandboxing - runaway scripts can be killed without having to crash the browser&lt;/li&gt;
    &lt;li&gt;Plugins - I'm against plug-ins in general (bar small amounts of flash and firebug), but allowing them to run in their own process space sounds like a good thing&lt;/li&gt;
    &lt;li&gt;UI look &amp;amp; feel - plus big points for minimalistic approach&lt;/li&gt;
    &lt;li&gt;Open source&lt;/li&gt;
    &lt;li&gt;Built-in DOM inspector&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;"Most Visited" sites home page - Browse histories don't do it for me. I need a programmable &amp;amp; static set of icons (Opera!)&lt;/li&gt;
    &lt;li&gt;No mouse gestures - again, maybe it's because &lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt;'s spoiled me, but without mouse gestures, old-school 'point and click' is plain slow&lt;/li&gt;
    &lt;li&gt;"Beta" - fair enough it's just been released, but is there anything that ever makes it past beta from google (gmail anyone)? Perhaps they should just register the "beta" thing as a trademark and be done with it&lt;/li&gt;
    &lt;li&gt;No Synrchonisation - This was something that got released with the new build of &lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt; a few months ago. It lets you log into your browser, and have it sync your bookmarks et al regardless of where you are or which computer you're on. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overall&lt;/p&gt;
&lt;p&gt;Very nice attempt, if I was coming from IE or Safari, or possibly even firefox chances are I'd convert (though if I was a firefox fanboy, I'd stick with FF out of principal). Chrome beats all contenders when it comes to observable performance, plus the internal wiring's more advanced. However, when it comes to useability, it just doesn't size up to &lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Since Chrome's open-source, I'm sure it's just a matter of time until the community creates enough plug-ins to mimic the UI smarts built in to &lt;a title="" href="http://geekswithblogs.net/dotNETPlayground/archive/2007/11/27/117134.aspx" rel=""&gt;Opera&lt;/a&gt;; but until then, I'm willing to sacrifice a couple of seconds of site performance &amp;amp; load time, to the incredible amount of time saved with navigation. &lt;/p&gt;
&lt;p&gt;Nice going Google, but I'll wait for the RC!&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/124876.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/124876.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/124876.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/124876.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Free Silverlight and WPF goodness for all!</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/08/15/124441.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/08/15/124441.aspx</id>
        <published>2008-08-15T07:58:5610:00:00</published>
        <updated>2008-08-15T08:00:27Z</updated>
        <content type="html">&lt;p&gt;WpfStyles.com (&lt;a href="http://www.wpfstyles.com/"&gt;http://www.wpfstyles.com&lt;/a&gt;) launched the other day (hooray!). The site lets WPF and Silverlight developers and designers upload their components and share them with the community.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.wpfstyles.com"&gt;&lt;img alt="WpfStyles.com" width="385" height="125" src="/images/geekswithblogs_net/dotNETPlayground/Logo.gif" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It's all free, so not only are you able to share your components, but you can also download those that other likeminded developers have put up there. &lt;/p&gt;
&lt;p&gt;If you have any such components that the community will find useful, throw them up there. I urge you to get behind this resource and show your support. &lt;img alt="" src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/regular_smile.gif" /&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/124441.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/124441.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/124441.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/124441.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Importing CSV flat files in SSIS - dealing with Double Quotes</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/08/14/124430.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/08/14/124430.aspx</id>
        <published>2008-08-14T12:57:3710:00:00</published>
        <updated>2008-08-14T12:57:37Z</updated>
        <content type="html">&lt;p&gt;I've gone through a number of phases in SSIS. The first was fascination, the next was anger, then came love, and now I'm somewhere in the middle. One major flaw I've noticed is how SSIS handles double quotes (") in imported flat file data, or should I say how it doesn't handle it at all?&lt;/p&gt;
&lt;p&gt;Simple scenario, I have a *csv file that I'm importing to a db table. The flat file is all text delimited using double quotes. A number of the fields contain literal double quotes, which in any CSV text delmited implementation you would normally escape by using another double quote delimeter. To illustrate:&lt;/p&gt;
&lt;p&gt;This: &lt;/p&gt;
&lt;p&gt;he cried out "SSIS!" in frustration&lt;/p&gt;
&lt;p&gt;Becomes This:&lt;/p&gt;
&lt;p&gt;"he cried out ""SSIS!"" in frustration"&lt;/p&gt;
&lt;p&gt;Simple, standard csv behaviour, parses fine in excel.&lt;/p&gt;
&lt;p&gt;Try importing to SSIS and your import will crash out, and if you try to preview that row you'll get: "T&lt;font face="Arial"&gt;he flat file parser does not support embedding text qualifiers in data"&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Solution? The only way I've found to get around this is to write your own escape functionality. I piggy-backed off html encoding and replaced literal quotes with &amp;amp;quot;  , and then used derived columns with &lt;font face="Arial"&gt;REPLACE(ImportedField,"&amp;amp;quot;","\"") to change them back prior to putting them in their destination table.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;I hate having to write work arounds like this, especially for functionality which should be part of the underlying core system. If anyone has a better way, please drop your comments in below. &lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/124430.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/124430.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/124430.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/124430.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Sql Server - How to split time into n minute groups</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/04/29/121735.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/04/29/121735.aspx</id>
        <published>2008-04-29T13:30:1110:00:00</published>
        <updated>2008-04-29T13:30:37Z</updated>
        <content type="html">&lt;p&gt;Another little data manipulation I've had to do recently is to split a heap of sql server datetime values into 15 minute segments (eg: 10:00, 10:15, 10:30 etc). Although there's no inherit function that I know about in sql server that achieves this, there's a nifty little trick using the modulus operator (%) that can do this.&lt;/p&gt;
&lt;div style="FONT-SIZE: 9pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: aqua"&gt;select&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;case &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;when datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;hour&lt;/span&gt;, DateTimeval) &amp;lt; &lt;span style="COLOR: yellow"&gt;12 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;then &lt;/span&gt;&lt;span style="COLOR: red"&gt;'AM' &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;else &lt;/span&gt;&lt;span style="COLOR: red"&gt;'PM'&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;end as &lt;/span&gt;Meridiem,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;Datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;hour&lt;/span&gt;, DateTimeval) &lt;span style="COLOR: aqua"&gt;as Hour&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;case &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;when &lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;minute&lt;/span&gt;, DateTimeval) % &lt;span style="COLOR: yellow"&gt;15 &lt;/span&gt;) &amp;lt; (&lt;span style="COLOR: yellow"&gt;15 &lt;/span&gt;/ &lt;span style="COLOR: yellow"&gt;2&lt;/span&gt;) &lt;span style="COLOR: aqua"&gt;then datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;minute&lt;/span&gt;, DateTimeval) - (&lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;minute&lt;/span&gt;, DateTimeval) % &lt;span style="COLOR: yellow"&gt;15&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;else &lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;minute&lt;/span&gt;, DateTimeval) + (&lt;span style="COLOR: yellow"&gt;15 &lt;/span&gt;- (&lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;minute&lt;/span&gt;, DateTimeval) % &lt;span style="COLOR: yellow"&gt;15&lt;/span&gt;))) % &lt;span style="COLOR: yellow"&gt;60&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;end as &lt;/span&gt;QuarterHour&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: aqua"&gt;from&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   MyTable&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Where DateTimeval is the column that holds the... date time value.&lt;/p&gt;
&lt;p&gt;Firstly the &amp;lt; (15/2) part determines the range of the midpoints (ie: the midpoint 15 ranges from 7.5 to 22.5).  Next it gets the minutes part from the value (eg: 10, 49, 15, etc), then does % 15. This will give the remainders (10, 04, 00). If the remainder is less that the range value (ie: &amp;lt; (15/2)), then by simply subtracting the remainder from the original value will give us the midpoint (eg: N/A, 49 - 4 = 45, 15 - 0 = 15). &lt;/p&gt;
&lt;p&gt;If, however, the remainder is &amp;gt; (15 / 2), then we need to add the difference of (15 - remainder) to get the upper midpoint value (eg: 10 + (15 - 10) = 5, 45, 15).&lt;/p&gt;
&lt;p&gt;And voila, the date time values are segmented into 15 minute chunks.&lt;/p&gt;
&lt;p&gt;Of course you can substitute 15 with however many minutes  you want to segment by (eg: 5, 10, 30 etc). &lt;/p&gt;
&lt;p&gt;Performance has been Ok. I ran this over 200,000 records and it took about 3 seconds on a shared dev server. Not bad.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/121735.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/121735.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/121735.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/121735.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Generating List of Dates</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/04/28/121696.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/04/28/121696.aspx</id>
        <published>2008-04-28T10:15:0510:00:00</published>
        <updated>2008-04-28T10:16:09Z</updated>
        <content type="html">&lt;p&gt;At times, especially when working with cubes with date/time dimensions, it's necessary for me to dynamically generate a list of date values for use in those dimensions. That single date dimension often services a number of cubes, and the range of date values can be determined from the min/max date values from serveral tables. &lt;/p&gt;
&lt;p&gt;I've written the following SQL that will retrieve the min/max date values, and create a single record for every day in that min/max range. It's useful to turn this sql into a view which will refresh itself automatically every time the cube calling it is processed.  &lt;/p&gt;
&lt;div style="FONT-SIZE: 9pt; BACKGROUND: black; COLOR: white; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: aqua"&gt;select&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(dw, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   + &lt;span style="COLOR: red"&gt;', ' &lt;/span&gt;+ &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(mm, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   + &lt;span style="COLOR: red"&gt;' ' &lt;/span&gt;+ &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(dd, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   + &lt;span style="COLOR: red"&gt;' ' &lt;/span&gt;+ &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(yy, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) [datename],&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: red"&gt;'Fiscal ' &lt;/span&gt;+ &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(yy, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) fiscalyearname,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(mm, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   + &lt;span style="COLOR: red"&gt;', ' &lt;/span&gt;+ &lt;span style="COLOR: aqua"&gt;datename&lt;/span&gt;(yy, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) fiscalmonthname,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;day&lt;/span&gt;, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) &lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;dayNumber,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;month&lt;/span&gt;, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) &lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;monthNumber,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   &lt;span style="COLOR: aqua"&gt;datepart&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;year&lt;/span&gt;, &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) &lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;yearNumber&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: aqua"&gt;from&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;   (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;select&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;dateadd&lt;/span&gt;(&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;day&lt;/span&gt;, &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            n1.val * &lt;span style="COLOR: yellow"&gt;10000 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            n2.val * &lt;span style="COLOR: yellow"&gt;1000 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            n3.val * &lt;span style="COLOR: yellow"&gt;100 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            n4.val * &lt;span style="COLOR: yellow"&gt;10 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            n5.val,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;cast&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;floor&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;cast&lt;/span&gt;(mindate &lt;span style="COLOR: aqua"&gt;as decimal&lt;/span&gt;(&lt;span style="COLOR: yellow"&gt;12&lt;/span&gt;,&lt;span style="COLOR: yellow"&gt;5&lt;/span&gt;))) &lt;span style="COLOR: aqua"&gt;as datetime&lt;/span&gt;)) &lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;from&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;0 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;val&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;1 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;2 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;3 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;4 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;5 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;6 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;7 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;8 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;9&lt;/span&gt;) n1,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;0 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;val&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;1 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;2 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;3 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;4 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;5 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;6 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;7 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;8 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;9&lt;/span&gt;) n2,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;0 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;val&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;1 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;2 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;3 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;4 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;5 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;6 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;7 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;8 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;9&lt;/span&gt;) n3,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;0 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;val&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;1 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;2 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;3 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;4 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;5 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;6 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;7 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;8 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;9&lt;/span&gt;) n4,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;0 &lt;/span&gt;&lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;val&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;1 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;2 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;3 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;4 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;5 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;6 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;7 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;8 &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all select &lt;/span&gt;&lt;span style="COLOR: yellow"&gt;9&lt;/span&gt;) n5,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;min&lt;/span&gt;(minDate) &lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;minDate, &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;max&lt;/span&gt;(maxDate) &lt;span style="COLOR: aqua"&gt;as &lt;/span&gt;maxDate &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;from &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (&lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &lt;span style="COLOR: aqua"&gt;min&lt;/span&gt;(date) minDate, &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &lt;span style="COLOR: aqua"&gt;max&lt;/span&gt;(date) maxdate&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;from &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &amp;lt;Data table 1&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;union all&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;select &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &lt;span style="COLOR: aqua"&gt;min&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;), &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &lt;span style="COLOR: aqua"&gt;max&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;date&lt;/span&gt;) &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;from &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;               &amp;lt;Data table 2&amp;gt;) dateVals&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;where &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;year&lt;/span&gt;(mindate) &amp;gt;= &lt;span style="COLOR: yellow"&gt;1980&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: aqua"&gt;and year&lt;/span&gt;(maxdate) &amp;lt;= &lt;span style="COLOR: aqua"&gt;dateadd&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;year&lt;/span&gt;, &lt;span style="COLOR: yellow"&gt;1&lt;/span&gt;, &lt;span style="COLOR: aqua"&gt;getdate&lt;/span&gt;())&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            ) c&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: aqua"&gt;where&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;dateadd&lt;/span&gt;(&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;day&lt;/span&gt;, &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        n1.val * &lt;span style="COLOR: yellow"&gt;10000 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        n2.val * &lt;span style="COLOR: yellow"&gt;1000 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        n3.val * &lt;span style="COLOR: yellow"&gt;100 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        n4.val * &lt;span style="COLOR: yellow"&gt;10 &lt;/span&gt;+&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        n5.val,&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: aqua"&gt;cast&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;floor&lt;/span&gt;(&lt;span style="COLOR: aqua"&gt;cast&lt;/span&gt;(mindate &lt;span style="COLOR: aqua"&gt;as decimal&lt;/span&gt;(&lt;span style="COLOR: yellow"&gt;12&lt;/span&gt;,&lt;span style="COLOR: yellow"&gt;5&lt;/span&gt;))) &lt;span style="COLOR: aqua"&gt;as datetime&lt;/span&gt;)) &amp;lt;= maxDate&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      ) dateVals&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/121696.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/121696.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/121696.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/121696.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Automatically Create Install Scripts with Sql Server</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/04/18/121331.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/04/18/121331.aspx</id>
        <published>2008-04-18T12:11:5310:00:00</published>
        <updated>2008-04-20T13:16:17Z</updated>
        <content type="html">&lt;p&gt;Problem: How can I &lt;strong&gt;QUICKLY&lt;/strong&gt; create an install script automatically in sql server every time I change my database? Creating an install script in sql server is pretty easy thanks to the "Script Database As..." command. However, this is generally a long winded process that doesn't give you too much control. &lt;/p&gt;
&lt;p&gt;In this post, I propose a solution to create build scripts with the following requirements&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Don't need to write any code &lt;/li&gt;
    &lt;li&gt;Easily maintainable &lt;/li&gt;
    &lt;li&gt;Can script schema AND data &lt;/li&gt;
    &lt;li&gt;Can specify which objects to script &lt;/li&gt;
    &lt;li&gt;Can run automatically before an MSI setup/deployment project is built &lt;/li&gt;
    &lt;li&gt;It has to be FREE&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first thing you need to do is download Microsoft's Database Publishing Wizard (&lt;font face="Arial"&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&amp;amp;displaylang=en&lt;/a&gt;&lt;/font&gt;)&lt;/p&gt;
&lt;p&gt;Next, in your development sql server, add two new accounts named: ScriptSchema and ScriptData. Make sure they are created as a sql login. At this point, don't give them any other access than public access to the database you want to script.&lt;/p&gt;
&lt;p&gt;Open the database you want to script. For each table/view/stored proc etc that you want to include in the install, grant view definition access to the ScriptSchema user as follows:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;grant view definition on &amp;lt;schema&amp;gt;.&amp;lt;object name&amp;gt; to scriptschema&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Next, for each table that you want to script the data for, grant select permission on that table to the ScriptData user, ie:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;grant select on &amp;lt;schema&amp;gt;.&amp;lt;table name&amp;gt; to scriptdata&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;You can double up, so for instance if you want to script the creation and population of data of a certain table called &lt;font face="Courier New"&gt;[dbo].[customers]&lt;/font&gt; you'd run the two commands:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;grant view definition on [dbo].[customers] to scriptschema&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;grant select on [dbo].[customers] to scriptdata&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Once you've set up the permissions, you can check out what will be scripted by connecting to the database as the scriptschema and scriptdata users. As you've now defined what will be scripted, it's time to do the scripting itself.&lt;/p&gt;
&lt;p&gt;Jump out into a cmd.exe, and run the two commands; &lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;sqlpubwiz script -C "data source=[server]; initial catalog=[database]; uid=scriptschema; pwd=password;" schema.sql -schemaonly -f&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;sqlpubwiz script -C "data source=[server]; initial catalog=[database]; uid=scriptdata; pwd=password;" data.sql -dataonly -f&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The first command connects to the database using the scriptschema account, and generates the definition of all the objects it can see, ie: those which you gave grant view definition access to.&lt;/p&gt;
&lt;p&gt;Likewise the second command connects to teh database using the scriptdata account and generates the scripts to insert the data, based on all the tables it can select from.&lt;/p&gt;
&lt;p&gt;You now have two scripts: schema.sql, data.sql. You can add these to your msi/setup projects in visual studio (outside the scope of this post). Furthermore you can then add the two commands mentioned to the pre-build events of your setup's resource project to build the install scripts prior to the MSI etc being built. &lt;/p&gt;
&lt;p&gt;I really like this solution to automatically generate sql install scripts. I feel it's elegant, there's no code to be maintained, and no manual updating of sql scripts every time you change the database. &lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/121331.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/121331.aspx</wfw:comment>
        <slash:comments>6</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/121331.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/121331.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Get date without time in Sql Server</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/03/31/120874.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/03/31/120874.aspx</id>
        <published>2008-03-31T11:45:3310:00:00</published>
        <updated>2008-03-31T11:45:33Z</updated>
        <content type="html">&lt;p&gt;There are times when you need to write a query joining on dates, that is the day of a date, but not worry about the time portion. Without using the between x and y, as sometimes this isn't possible from places like SSAS Data source views, what's the most efficient way to remove the time part of a datetime?&lt;/p&gt;
&lt;p&gt;There are a number of ways to drop off the time part, as shown here:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;select CONVERT(datetime, CONVERT(varchar(10), c.date, 111), 111) from dbo.phonecalls c&lt;/font&gt; &lt;br /&gt;
go &lt;/font&gt;&lt;/p&gt;
&lt;div&gt;&lt;font size="+0"&gt;&lt;font size="2"&gt;&lt;span class="301115200-31032008"&gt;&lt;font face="Courier New"&gt;&lt;font color="#ff0000"&gt;select cast(CAST(YEAR(c.date) AS VARCHAR(4)) + '/' +&lt;br /&gt;
           CAST(MONTH(c.date) AS VARCHAR(2)) + '/' +&lt;br /&gt;
           CAST(DAY(c.date) AS VARCHAR(2)) as datetime) from dbo.phonecalls c&lt;/font&gt;&lt;br /&gt;
           &lt;br /&gt;
go&lt;br /&gt;
&lt;font color="#008000"&gt;select CAST(FLOOR(CAST(c.date AS DECIMAL(12, 5))) AS DATETIME) from dbo.phonecalls c&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="+0"&gt;&lt;font face="Courier New" size="2"&gt;&lt;span class="301115200-31032008"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;After clearing the query cache for the server (&lt;font size="+0"&gt;&lt;font face="Courier New" size="2"&gt;&lt;span class="301115200-31032008"&gt;dbcc freeproccache&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;) I executed the above in sequence, and got the following execution times:&lt;/div&gt;
&lt;div&gt; 
&lt;div&gt;&lt;font face="Arial" color="#0000ff" size="2"&gt;150871&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Arial" size="2"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="Arial" color="#ff0000" size="2"&gt;186319&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Arial" size="2"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="Arial" color="#008000" size="2"&gt;94119&lt;/font&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;So it appears that casting the date to a 5 point decimal, dropping the decimal portion, and then casting back to a date time is by far the most efficient. I'm putting this down the fact that it's a completely numerical operation, and doesn't resort to casting to different value types (ie: varchar). &lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/120874.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/120874.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/120874.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/120874.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Sanitise your database input</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/01/31/119104.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/01/31/119104.aspx</id>
        <published>2008-01-31T08:13:4210:00:00</published>
        <updated>2008-01-31T08:13:42Z</updated>
        <content type="html">&lt;p&gt;Saw this little strip today from &lt;a href="http://xkcd.com/"&gt;http://xkcd.com/&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;img height="205" alt="Courtesy of http://xkcd.com/" width="666" src="/images/geekswithblogs_net/dotNETPlayground/exploits_of_a_mom.png" /&gt;&lt;/p&gt;
&lt;p&gt;SQL injection's a nasty by-product of poor development. Anywhere a user can enter data, there's the potential for an exploit. In my opinion, performing input validation on the web/ui layer is repetitive and insecure. I've always taken the approach to move all that to the Data layer. &lt;/p&gt;
&lt;p&gt;Here resides a few exclusive set of methods that are the only ones that can interface with the database. Performing input checking here ensures that everything that goes to the database isn't going to cause any grief. Furthermore you can do it once and not have to worry about validating input from every new field you put on your display layer. &lt;/p&gt;
&lt;p&gt;Furthermore it's unecessary and bad practice to be generating sql in any of your layers except for the few times when it's necessary to gen dynamic sql in stored procs. Effectively if you design towards these sorts of goals, you can pretty much guarantee little Bobby tables won't be causing you any issues.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/119104.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/119104.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/119104.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/119104.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Non-data bound query parameters in MDX datasets for SSRS</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/01/30/119083.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/01/30/119083.aspx</id>
        <published>2008-01-30T20:18:3810:00:00</published>
        <updated>2008-01-30T20:18:38Z</updated>
        <content type="html">&lt;p&gt;This little one isn't very obvious and can cause a lot of hair pulling, so I decided to write it down here.&lt;/p&gt;
&lt;p&gt;Basically in reporting services you can make use of reporting parameters using a combination of dataset query parameters and Member(&amp;lt;&amp;lt;string&amp;gt;&amp;gt;) functions. Hence you can define a parameter that returns a string ie: '[Organisation].[Hierarchy].&amp;amp;[1232]'&lt;/p&gt;
&lt;p&gt;Sometimes, like today, I need to send down just the Ids themselves, as these get plucked directly out of a querystring, so I might have say: 1232,144,664  as my key values. I wrote a quick CLR function that I plugged into analysis services which will convert n values into a string of:&lt;/p&gt;
&lt;p&gt;{[Organisation].[Hierarchy].&amp;amp;[1232],[Organisation].[Hierarchy].&amp;amp;[144],[Organisation].[Hierarchy].&amp;amp;[664]}, which then gets returned as a set and life goes on.&lt;/p&gt;
&lt;p&gt;However, when I was defining the query parameters, @DepartmentID (and all the other parameters) needed a default value. This was annoying as this value was bound to the [Organisation] dimension, and hence it would insist on binding to the values therein.&lt;/p&gt;
&lt;p&gt;Little did I know that you're allowed to define a query parameter that's NOT bound, although it still needs a default parameter. Unbinding from the dimension will save a headache, and let you pass parameters in as mentioned.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/119083.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/119083.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/119083.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/119083.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Compressing ASPX pages with IIS</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/dotNETPlayground/archive/2008/01/22/118767.aspx" />
        <id>http://geekswithblogs.net/dotNETPlayground/archive/2008/01/22/118767.aspx</id>
        <published>2008-01-22T12:58:2710:00:00</published>
        <updated>2008-01-22T12:58:27Z</updated>
        <content type="html">&lt;p&gt;GZip / DEFLATE compression's a quick and simple trick you can employ to reduce the size of your pages that get sent down the wire. IIS supports this natively (IIS5 &amp;amp; IIS6, the latter improving the process somewhat). The best part is that it's quick simple to get up and running.&lt;/p&gt;
&lt;p&gt;Jump onto the box you run IIS in as admin, open up a new cmd, and punch away the following:&lt;/p&gt;
&lt;p&gt;go to your &lt;strong&gt;InetPub\adminscripts &lt;/strong&gt;directory&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;net stop iisadmin&lt;/strong&gt;   //To stop the services&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions  "aspx" "asp" "dll"&lt;/strong&gt;  //Register the additional types to compress&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;net start w3svc&lt;/strong&gt;   //Start the services back up&lt;/p&gt;
&lt;p&gt;This sort of technology has been around for a while, so only users running on the most outdated browsers might have a few issues. But for the rest of us, compression can significantly reduce download times. For instance a Reporting Services report would come down as 500KB uncompressed, but only 50KB when compressed with GZip. That's 10% of the original. &lt;/p&gt;
&lt;p&gt;That's quite significant when you're looking at slow connections, and the additional CPU load/time to compress is irrelevant when compared to savings in the download time side of things.&lt;/p&gt;
&lt;p&gt;A quick side note is that there's hardly any difference between GZip and DEFLATE compression technologies. They'll both give you pretty much the same ratio's, but from memory DEFLATE contains a number of additional header fields, hence will be a number of bytes larger than its GZip counterpart.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/dotNETPlayground/aggbug/118767.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/dotNETPlayground/comments/118767.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/dotNETPlayground/comments/commentRss/118767.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/dotNETPlayground/services/trackbacks/118767.aspx</trackback:ping>
    </entry>
</feed>