<?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>WorldofCode.com &#187; SQL</title>
	<atom:link href="http://www.worldofcode.com/category/coding/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.worldofcode.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 05 Jan 2011 01:32:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SQL Server Database stuck in Restoring state</title>
		<link>http://www.worldofcode.com/sql-server-database-stuck-in-restoring-state/</link>
		<comments>http://www.worldofcode.com/sql-server-database-stuck-in-restoring-state/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 12:00:00 +0000</pubDate>
		<dc:creator>WorldofCode</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Restore]]></category>

		<guid isPermaLink="false">http://www.worldofcode.com/sql-server-database-stuck-in-restoring-state/</guid>
		<description><![CDATA[From time to time your sql database will get stuck&#160;in Restoring state.&#160; Here are two different ways to get your database out of restoring state.&#160; RESTORE DATABASE MyDatabase&#160; &#160; &#160;FROM DISK = &#8216;MyDatabase.bak&#8217;&#160; &#160; &#160;WITH REPLACE,RECOVERY or Stop the service (MSSQLSERVER); Rename or delete the Database and Log files (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data&#8230;) or wherever [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>From time to time your sql database will get stuck&nbsp;in Restoring state.&nbsp; Here are two different ways to get your database out of restoring state.&nbsp;</p>
<blockquote>
<p><span class="pln">RESTORE DATABASE </span><span class="typ"><font color="#2b91af">MyDatabase</font></span><span class="pln">&nbsp;<br />
&nbsp; &nbsp;FROM DISK </span><span class="pun">=</span><span class="pln"> </span><span class="str"><font color="#800000">&#8216;MyDatabase.bak&#8217;</font></span><span class="pln">&nbsp;<br />
&nbsp; &nbsp;WITH REPLACE</span><span class="pun">,</span><span class="pln">RECOVERY</span></p>
</blockquote>
<div>or</div>
<ol>
<li>Stop the service (MSSQLSERVER);</li>
<li>Rename or delete the Database and Log files (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data&#8230;) or wherever you have the files;</li>
<li>Start the service (MSSQLSERVER);</li>
<li>Delete the database with problem;</li>
<li>Restore the database again.</li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.worldofcode.com/sql-server-database-stuck-in-restoring-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use the Union statement with a dynamic order by</title>
		<link>http://www.worldofcode.com/how-to-use-the-union-statement-with-a-dynamic-order-by/</link>
		<comments>http://www.worldofcode.com/how-to-use-the-union-statement-with-a-dynamic-order-by/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 01:28:22 +0000</pubDate>
		<dc:creator>WorldofCode</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[derived table]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[union]]></category>

		<guid isPermaLink="false">http://www.worldofcode.com/how-to-use-the-union-statement-with-a-dynamic-order-by/</guid>
		<description><![CDATA[I don&#8217;t use the Union statement to much in my SQL coding but today I needed to use it to combine results from two separate tables.  But I ran into an error when I wanted to add in my usual code for doing a dynamic order by.  SQL wouldn&#8217;t run my query and output this [...]]]></description>
			<content:encoded><![CDATA[<p><br />
I don&#8217;t use the Union statement to much in my SQL coding but today I needed to use it to combine results from two separate tables.  But I ran into an error when I wanted to add in my usual code for doing a dynamic order by.  SQL wouldn&#8217;t run my query and output this error message.</p>
<p><span style="color: #ff0000;">ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.</span></p>
<p> To fix this problem I put my Union statement into a derived table by doing the following.</p>
<blockquote><p>SELECT * FROM (</p>
<p>SELECT Column1, Column2 FROM Table_A</p>
<p>UNION ALL</p>
<p>SELECT Column1, Column2 FROM Table_B</p>
<p>) DerivedTableName (Column1, Column2)</p></blockquote>
<p>Next I added in my dynamic Order By code as such.</p>
<blockquote><p>SELECT * FROM (</p>
<p>SELECT Column1, Column2 FROM Table_A</p>
<p>UNION ALL</p>
<p>SELECT Column1, Column2 FROM Table_B</p>
<p>) DerivedTableName (Column1, Column2)</p>
<p>ORDER BY</p>
<p>CASE @OrderBy WHEN &#8216;Column1ASC&#8217; THEN Column1 END ASC,</p>
<p>CASE @OrderBy WHEN &#8216;Column1DESC&#8217; THEN Column1 END DESC</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.worldofcode.com/how-to-use-the-union-statement-with-a-dynamic-order-by/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

