<?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>blog.richardramdat.com &#187; SQL</title>
	<atom:link href="http://blog.richardramdat.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.richardramdat.com</link>
	<description></description>
	<lastBuildDate>Tue, 17 Jan 2012 01:49:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging in SQL Management Studio</title>
		<link>http://blog.richardramdat.com/2008/12/debugging-in-sql-management-studio/</link>
		<comments>http://blog.richardramdat.com/2008/12/debugging-in-sql-management-studio/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 20:33:17 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.richardramdat.com/?p=15</guid>
		<description><![CDATA[One common frustration is trying to debug SQL queries using the built-in editor within Microsoft SQL Server 2005 Management Studio. The database will kindly inform you of any errors when you attempt to execute a query, and also provide a line number. But that&#8217;s about it.
Compared to the error highlighting features available in Visual Studio,  [...]]]></description>
			<content:encoded><![CDATA[<p>One common frustration is trying to debug SQL queries using the built-in editor within Microsoft SQL Server 2005 Management Studio. The database will kindly inform you of any errors when you attempt to execute a query, and also provide a line number. But that&#8217;s about it.</p>
<p>Compared to the error highlighting features available in Visual Studio,  its hard to imagine that Management Studio is developed by the same company.</p>
<p>For example take the following error:</p>
<div id="attachment_16" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.richardramdat.com/wp-content/uploads/2008/12/blog_sqlerror1.jpg"><img class="size-medium wp-image-16" title="blog_sqlerror1" src="http://blog.richardramdat.com/wp-content/uploads/2008/12/blog_sqlerror1-300x171.jpg" alt="Example of Sql Error" width="300" height="171" /></a><p class="wp-caption-text">Example of Sql Error</p></div>
<p>The editor informs me that I have two errors, one on Line 4 and another on Line 2. But here&#8217;s the thing &#8211; if I go to line 2 or 4 of my script, I find nothing pertaining to the error. So what&#8217;s going on?</p>
<p>The query parser conveniently restarts counting line numbers whenever it encounters a code block, so anything in between a BEGIN and END statement, starts at line 0 again. If you have multiple code blocks in a script, then line numbers are completely useless.</p>
<p>So how do you find out which line is actually causing the error?</p>
<p>In the most poorly designed way ever imagined,  Microsoft has graciously decided to help you out by allowing you to double click on those error messages and be taken to the exact part of your code that is causing the error.</p>
<p>And then that leads one to wonder &#8211; if there is some way for this double-click function to map the error message to the actually line number in the editor, then why isn&#8217;t this function used to display the &#8220;real&#8221; line numbers for error messages, as opposed to the completely useless line numbers that are shown now?</p>
<p>Considering the amount of money organizations spend on SQL Server, I find this type of design short-sighted.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardramdat.com/2008/12/debugging-in-sql-management-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T-SQL Return True / False based on Is Null</title>
		<link>http://blog.richardramdat.com/2008/11/t-sql-return-true-false-based-on-is-null/</link>
		<comments>http://blog.richardramdat.com/2008/11/t-sql-return-true-false-based-on-is-null/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 13:35:59 +0000</pubDate>
		<dc:creator>richard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.richardramdat.com/?p=5</guid>
		<description><![CDATA[So I&#8217;m working on a project where images are uploaded to a database table. The table has an image column, and if there is no image, then the column is just null,  but otherwise the bytes for the image are stored.
An ASPX page takes in the row id for this table via querystring and serves up the [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m working on a project where images are uploaded to a database table. The table has an image column, and if there is no image, then the column is just null,  but otherwise the bytes for the image are stored.</p>
<p>An ASPX page takes in the row id for this table via querystring and serves up the bytes from the column as an actual image.</p>
<p>On a separate page, I&#8217;m displaying the contents of the table in a per-record listing, if there is an image, then I display a thumbnail by calling the aforementioned aspx image page.</p>
<p>So my problem? If only some records have images, then how do I know when to call the aspx image page? I could do something quick like:</p>
<p>SELECT ItemID, ItemName, ItemDescription, ItemImage FROM Table</p>
<p>And then check to see if ItemImage is null. But what if it isn&#8217;t null? I can&#8217;t do anything with the bytes I have, because I have a separate page for displaying the image. So in essence, I&#8217;m calling back data (potentially large data) that I don&#8217;t need.</p>
<p>So what I really want is a query that looks like:</p>
<p>SELECT ItemID, ItemName, ItemDescription, HasImage FROM Table</p>
<p>Where HasImage is a bit (true/false) column, telling me if there&#8217;s an image for this item or not. But I don&#8217;t have a column in my table called HasImage and its too much work to implement one.</p>
<p>So the best way to solve this?</p>
<p>SELECT ItemID, ItemName, ItemDescription, (CASE WHEN ItemImage IS NOT NULL THEN 1 ELSE 0 END) AS HasImage FROM Table</p>
<p>This now tells me if this record has an image without actually bringing back the bytes for the image.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardramdat.com/2008/11/t-sql-return-true-false-based-on-is-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

