<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>{ Code: Impossible } &#187; SQL</title>
	<atom:link href="http://codeimpossible.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:58:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get databases in sql backup plan with sql</title>
		<link>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/</link>
		<comments>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 03:37:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database-maintenance]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=891</guid>
		<description><![CDATA[I helped Tamara figure this out the other day and thought others might want to know. She needed to know which databases would be backed up when a given backup plan was executed. The server was a sql 2000 server and the machine she was using didn&#8217;t have enterprise manager installed.

    SELECT
 [...]]]></description>
			<content:encoded><![CDATA[<p>I helped Tamara figure this out the other day and thought others might want to know. She needed to know which databases would be backed up when a given backup plan was executed. The server was a sql 2000 server and the machine she was using didn&#8217;t have enterprise manager installed.</p>
<pre style="display: block; overflow: auto: width: 550px;"><code class="prettyprint">
    SELECT
        *
    FROM
        msdb.dbo.sysdbmaintplans
    LEFT JOIN msdb.dbo.sysdbmaintplan_databases
    ON msdb.dbo.sysdbmaintplan_databases.plan_id = msdb.dbo.sysdbmaintplans.plan_id
    WHERE
        msdb.dbo.sysdbmaintplans.plan_name = 'PUT YOUR PLAN NAME HERE'
</code></pre>
<p>So if anyone out there finds themselves needing to know which databases will be backed up by a given backup plan, and for whatever reason you don&#8217;t have Sql Management Studio or Enterprise Manager then this should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft .Net Framework Public Classes Data Dump</title>
		<link>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/</link>
		<comments>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 06:24:27 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=748</guid>
		<description><![CDATA[I&#8217;ve wrapped up work on v0.4 of the Jsoq Console, and the insanely strenuous release cycle for v0.1 of WhatDidIJustEat.com so I&#8217;m starting another side project tonight.
Ever been working with a programming language you&#8217;re not 100% familiar with and find yourself wondering:
Is this function a built-in function or in some included library?
What assembly is this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve wrapped up work on <a href="http://codeimpossible.com/jsoq">v0.4 of the Jsoq Console</a>, and the insanely strenuous release cycle for v0.1 of <a href="http://whatdidijusteat.com">WhatDidIJustEat.com</a> so I&#8217;m starting another side project tonight.</p>
<p>Ever been working with a programming language you&#8217;re not 100% familiar with and find yourself wondering:</p>
<blockquote><p><em>Is this function a built-in function or in some included library?<br />
What assembly is this class in again?<br />
Can I name my class XXXX without conflicting with another class?<br /></em></p></blockquote>
<p>I&#8217;ve had these questions recently and found myself annoyed and frustrated to no end (PHP, I&#8217;m looking at you) so I&#8217;ve decided to build a system to keep track of this stuff for me :D. </p>
<p>The first thing on my list (because it was the easiest) was to do a data dump of all the public classes in the .Net Framework, including the ones in my GAC, and store some metadata for each one in a database table. I&#8217;ve just finished this step and thought that this data might be useful, so I&#8217;m posting it here. </p>
<p>Currently the fields included in the data dump are:</p>
<p><code><br />
[namespace] = The namespace that the class exists in (ex: System.Collections.Generic)<br />
[class_name] = The name of the class (ex: StringBuilder)<br />
[assembly_fullname] = The display name of the assembly (ex: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)<br />
[assembly_file] = The full file path to the assembly (ex: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll)<br />
[framework_name] = The framework that uses this class, for this dump they will all be 'Microsoft .Net'<br />
[framework_version] = The framework version that uses this class (ex: v.2.0.50727)<br />
</code></p>
<p>The .sql file takes about 18 seconds to run to completion on my AMD Athlon X2 2.53ghz machine with 4gb of RAM.</p>
<p>If you&#8217;re curious about how I generated the .sql file, below is the code I used to find all the classes. It&#8217;s not pretty but then again it was just meant to get the data into the database. Just paste the code into a new console app and run it in a command window like so:</p>
<p><code> [application_name].exe &gt; c:\classes.sql</code></p>
<p>Or, you can <a href="http://www.box.net/shared/u8vsuy9lz1">download the .sql file I&#8217;ve generated</a> (it will also create the table you need to store the data).</p>
<pre class="prettyprint"><code>
static void Main(string[] args)
{
	var dictionary = new Dictionary<string, string>(){
		{ "v2.0.50727", @"C:\Windows\Microsoft.NET\Framework\v2.0.50727" },
		{ "v3.0", @"C:\Windows\Microsoft.NET\Framework\v3.0" },
		{ "v3.5", @"C:\Windows\Microsoft.NET\Framework\v3.5" },
		{ "v???", @"c:\windows\assembly\gac" }
	};

	var types = new List<Type>();

	foreach (var pair in dictionary)
	{
		var path = pair.Value;

		var assemblies = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);

		foreach (string file in assemblies)
		{
			try
			{
				Assembly asm = Assembly.LoadFile(file);

				foreach (Type t in asm.GetTypes())
				{
					if (t.IsPublic)
					{
						Console.WriteLine(String.Format(
							"INSERT INTO Classes (" +
								"[namespace], " +
								"class_name, " +
								"assembly_fullname, " +
								"assembly_file, " +
								"framework_name, " +
								"framework_version" +
							") " +
							"VALUES (" +
								"'{0}', " +
								"'{1}', " +
								"'{2}', " +
								"'{3}', " +
								"'Microsoft .Net', " +
								"'{4}'" +
							")",
							String.IsNullOrEmpty(t.Namespace) ?
								"GLOBAL" :
								t.Namespace,
							t.Name
								.Replace("`1", "<T>")
								.Replace("`2", "<T1,T2>")
								.Replace("`3", "<T1,T2,T3>"),
							t.Assembly.FullName,
							t.Assembly.Location,
							pair.Key == "v???" ?
								t.Assembly.GetName().Version.ToString() :
								pair.Key
						));
					}
				}
			}
			catch { }
		}
	}
}
</code></pre>
<p>If you found this useful, let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dear Sql management studio, just let me save my database table!!</title>
		<link>http://codeimpossible.com/2009/09/16/dear-sql-management-studio/</link>
		<comments>http://codeimpossible.com/2009/09/16/dear-sql-management-studio/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 02:57:52 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql-server-2008]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=646</guid>
		<description><![CDATA[If you&#8217;re like me, you recently upgraded to Sql Server 2008 (or just installed the Management Studio). If you&#8217;re really like me you found the &#8220;Saving changes is not permitted&#8221; dialog that pops up every time you try to save a modified table annoying. 
You may not have found it annoying enough to investigate but [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, you recently upgraded to Sql Server 2008 (or just installed the Management Studio). If you&#8217;re really like me you found the &#8220;Saving changes is not permitted&#8221; dialog that pops up every time you try to save a modified table annoying. </p>
<p>You may not have found it annoying enough to investigate but I sure did. I don&#8217;t remember Management Studio 2005 complaining when I changed a table and saved it. Why the change in 2008?</p>
<p>Well, anyway, here&#8217;s your chance to get rid of that dialog once and for all.</p>
<p>In Sql Management Studio, go to <b>Tools</b> -> <b>Options</b>, expand down the <b>Designers</b> node, and select <b>Table and Database Designers</b>. In the <b>Table Options</b> section uncheck <b>Prevent saving changes that require table re-creation</b> and you&#8217;re done! </p>
<p>You can now change your database tables hassle free!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/09/16/dear-sql-management-studio/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DateTime to &quot;Friendly&quot; Date</title>
		<link>http://codeimpossible.com/2008/09/08/datetime-to-friendly-date/</link>
		<comments>http://codeimpossible.com/2008/09/08/datetime-to-friendly-date/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 16:49:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://pistalwhipped.wordpress.com/?p=202</guid>
		<description><![CDATA[I really like it when an application presents dates in a friendly &#8220;n Hours Ago&#8221; format. Mostly because I&#8217;m lazy and hate to do extra brain-work. John Resig created &#8220;pretty date&#8221; and it&#8217;s insanely useful. It also plugs into JQuery very easily.
But on the project I am working on it made more sense to provide [...]]]></description>
			<content:encoded><![CDATA[<p>I really like it when an application presents dates in a friendly &#8220;n Hours Ago&#8221; format. Mostly because I&#8217;m lazy and hate to do extra brain-work. <a title="Pretty Date.js" href="http://ejohn.org/blog/javascript-pretty-date/" target="_blank">John Resig created &#8220;pretty date&#8221;</a> and it&#8217;s insanely useful. It also plugs into JQuery very easily.</p>
<p>But on the project I am working on it made more sense to provide this functionality within the database. So I created a pretty date function for SQL.</p>
<p>[sourcecode language="SQL"]<br />
CREATE FUNCTION dbo.GetFriendlyDateTimeValue<br />
(<br />
	@CompareDate DateTime<br />
)<br />
RETURNS nvarchar( 48 )<br />
AS<br />
BEGIN<br />
	DECLARE @Now DateTime<br />
	DECLARE @Hours int<br />
	DECLARE @Suff nvarchar(256)<br />
	DECLARE @Found bit</p>
<p>	SET @Found = 0<br />
	SET @Now = getDate()<br />
	SET @Hours = DATEDIFF(MI, @CompareDate, @Now)/60</p>
<p>	IF @Hours <= 1<br />
	BEGIN<br />
		SET @Suff = 'Just Now'<br />
		SET @Found = 1<br />
		RETURN @Suff<br />
	END</p>
<p>	IF @Hours < 24<br />
	BEGIN<br />
		SET @Suff = ' Hours Ago'<br />
		SET @Found = 1<br />
	END</p>
<p>	IF @Hours >= 8760 AND @Found = 0<br />
	BEGIN<br />
		SET @Hours = @Hours / 8760<br />
		SET @Suff = &#8216; Years Ago&#8217;<br />
		SET @Found = 1<br />
	END</p>
<p>	IF @Hours >= 720 AND @Found = 0<br />
	BEGIN<br />
		SET @Hours = @Hours / 720<br />
		SET @Suff = &#8216; Months Ago&#8217;<br />
		SET @Found = 1<br />
	END</p>
<p>	IF @Hours >= 168 AND @Found = 0<br />
	BEGIN<br />
		SET @Hours = @Hours / 168<br />
		SET @Suff = &#8216; Weeks Ago&#8217;<br />
		SET @Found = 1<br />
	END</p>
<p>	IF @Hours >= 24 AND @Found = 0<br />
	BEGIN<br />
		SET @Hours = @Hours / 24<br />
		SET @Suff = &#8216; Days Ago&#8217;<br />
		SET @Found = 1<br />
	END</p>
<p>	RETURN Convert(nvarchar, @Hours) + @Suff</p>
<p>END<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/09/08/datetime-to-friendly-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Forget: SQL 2008 Virtual Event</title>
		<link>http://codeimpossible.com/2008/01/03/dont-forget-sql-2008-virtual-event/</link>
		<comments>http://codeimpossible.com/2008/01/03/dont-forget-sql-2008-virtual-event/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 04:20:58 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.pistalwhipped.net/bl/og/2008/01/03/dont-forget-sql-2008-virtual-event/</guid>
		<description><![CDATA[Hey this is just a reminder to everyone, don&#8217;t forget that the SQL 2008 Virtual Event is open for registration. You can do so over at http://events.unisfair.com/rt/sql~jan08/?code=solidqweb .
Topics include:

Developing Data-Centric Applications with SQL Server 2008
Getting a Handle on Data Cleansing in SSIS
Performance Tuning
Reporting Services with SQL Server 2008
SQL Server Virtualization

The even starts on Jan 24th [...]]]></description>
			<content:encoded><![CDATA[<p>Hey this is just a reminder to everyone, don&#8217;t forget that the SQL 2008 Virtual Event is open for registration. You can do so over at <a href="http://events.unisfair.com/rt/sql~jan08/?code=solidqweb" target="_blank">http://events.unisfair.com/rt/sql~jan08/?code=solidqweb .</a></p>
<p>Topics include:</p>
<ul>
<li>Developing Data-Centric Applications with SQL Server 2008</li>
<li>Getting a Handle on Data Cleansing in SSIS</li>
<li>Performance Tuning</li>
<li>Reporting Services with SQL Server 2008</li>
<li>SQL Server Virtualization</li>
</ul>
<p>The even starts on Jan 24th and runs from 11am to 4:15pm EST. Register now!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/01/03/dont-forget-sql-2008-virtual-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
