<?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>gregs &#187; MS SQL</title>
	<atom:link href="http://gregs.tcias.co.uk/category/comps/database/ms-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregs.tcias.co.uk</link>
	<description>helping me remember what I figure out</description>
	<lastBuildDate>Fri, 03 Feb 2012 01:04:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Find duplicates</title>
		<link>http://gregs.tcias.co.uk/2010/09/21/find-duplicates/</link>
		<comments>http://gregs.tcias.co.uk/2010/09/21/find-duplicates/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 09:47:50 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[find duplicates]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://gregs.tcias.co.uk/?p=570</guid>
		<description><![CDATA[Because I have to keep running this script and thus look it up, keeping it here for handy and quick reference PLAIN TEXT CODE: select count&#40;id&#41; from database.dbo.tablename group by id having count&#40;id&#41;&#62; 1]]></description>
			<content:encoded><![CDATA[<p>Because I have to keep running this script and thus look it up, keeping it here for handy and quick reference</p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">select count<span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">from database.<span style="">dbo</span>.<span style="">tablename</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">group by id</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">having count<span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#800000;color:#800000;">1</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2010/09/21/find-duplicates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL to XML</title>
		<link>http://gregs.tcias.co.uk/2007/08/29/sql-to-xml/</link>
		<comments>http://gregs.tcias.co.uk/2007/08/29/sql-to-xml/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 05:12:45 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://gregs.teacupinastorm.com/?p=455</guid>
		<description><![CDATA[Just came across this neat trick that uses SQL to generate XML on the fly: PLAIN TEXT CODE: DECLARE @x xml SET @x=&#40;select geoAreaCode , geoLevelCode , geoLevelId , geoAreaId from tbl_geoLevel where uuid = for xml raw&#40;'geoArea'&#41;, root&#40;'geoAreas'&#41;, type&#41; &#8230; <a href="http://gregs.tcias.co.uk/2007/08/29/sql-to-xml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just came across this neat trick that uses SQL to generate XML on the fly:</p>
<div class="igBar"><span id="lcode-4"><a href="#" onclick="javascript:showPlainTxt('code-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-4">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">DECLARE @x xml</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SET @x=<span style="color:#006600; font-weight:bold;">&#40;</span>select geoAreaCode</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">, geoLevelCode</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">, geoLevelId</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">, geoAreaId</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">from tbl_geoLevel</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">where uuid =</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">for xml raw<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'geoArea'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, root<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'geoAreas'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, type<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SELECT @x AS geoAreaInfo </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The above will create an XML structure that has a root value of geoAreas and child elements of geoArea for each row found.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2007/08/29/sql-to-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beyond SQL injection attacks</title>
		<link>http://gregs.tcias.co.uk/2006/11/23/beyond-sql-injection-attacks/</link>
		<comments>http://gregs.tcias.co.uk/2006/11/23/beyond-sql-injection-attacks/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://gregs.tcias.co.uk/?p=157</guid>
		<description><![CDATA[Courtesy of Slashdot a reminder that you should also worry about other types of injection attacks. Don't you just wish that everybody would play nice? UPDATE In a similar vein, Nadav Samet covers off in more detail Cross Site Scripting &#8230; <a href="http://gregs.tcias.co.uk/2006/11/23/beyond-sql-injection-attacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Courtesy of Slashdot a reminder that you should also worry about <a title="Malicious Code Injection: It's Not Just for SQL Anymore" href="http://www.site-reference.com/articles/Website-Development/Malicious-Code-Injection-It-s-Not-Just-for-SQL-Anymore.html">other types of injection attacks</a>. Don't you just wish that everybody would play nice?</p>
<p>UPDATE</p>
<p>In a similar vein, Nadav Samet <a title="Prepare for Attack!â€”Making Your Web Applications More Secure" href="http://www.thesamet.com/blog/2007/01/16/prepare-for-attack%e2%80%94making-your-web-applications-more-secure/">covers off in more detail</a> Cross Site Scripting attacks, how they work and what you can do to protect your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2006/11/23/beyond-sql-injection-attacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogParser</title>
		<link>http://gregs.tcias.co.uk/2006/11/23/logparser/</link>
		<comments>http://gregs.tcias.co.uk/2006/11/23/logparser/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[log]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[parse]]></category>

		<guid isPermaLink="false">http://gregs.tcias.co.uk/?p=140</guid>
		<description><![CDATA[Charlie Arehart has a handy little article published in this months CFDJ on using Microsoft's Log Parser tool, which allows you to write SQL like statements against your CFMX log files. Couldn't find a publicly accessible link, but if you &#8230; <a href="http://gregs.tcias.co.uk/2006/11/23/logparser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Charlie Arehart has a handy little article published in this months CFDJ on using <a title="Download Details: Log Parser 2.2" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;displaylang=en">Microsoft's Log Parser tool</a>, which allows you to write SQL like statements against your CFMX log files. Couldn't find a publicly accessible link, but if you keep an eye on his <a title="Articles by Charlie Arehart" href="http://carehart.org/articles.cfm">articles page</a>, I am sure he'll update it as soon as it is available.</p>
<h4>Update</h4>
<p>Charlie dropped me a note last week to let me know that the article can be found <a title="Monitoring Your ColdFusion Environment With the Free Log Parser Toolkit" href="http://coldfusion.sys-con.com/read/296223.htm">on-line here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2006/11/23/logparser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CFMX &#8211; MSDE connection refused error</title>
		<link>http://gregs.tcias.co.uk/2005/12/16/cfmx-msde-connection-refused-error/</link>
		<comments>http://gregs.tcias.co.uk/2005/12/16/cfmx-msde-connection-refused-error/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://gregs.tcias.co.uk/?p=156</guid>
		<description><![CDATA[I just started using MSDE for local development again and after creating my first DSN through the ColdFusion administrator I encountered the following problem: PLAIN TEXT CODE: # Connection verification failed for data source: SMS java.sql.SQLException: &#91;Macromedia&#93;&#91;SQLServer JDBC Driver&#93;Error establishing &#8230; <a href="http://gregs.tcias.co.uk/2005/12/16/cfmx-msde-connection-refused-error/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just started using MSDE for local development again and after creating my first DSN through the ColdFusion administrator I encountered the following problem:</p>
<div class="igBar"><span id="lcode-7"><a href="#" onclick="javascript:showPlainTxt('code-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-7">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># Connection verification failed for data source: SMS</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">java.<span style="">sql</span>.<span style="">SQLException</span>: <span style="color:#006600; font-weight:bold;">&#91;</span>Macromedia<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer JDBC Driver<span style="color:#006600; font-weight:bold;">&#93;</span>Error establishing socket. <span style="">Connection</span> refused: connect</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">The root cause was that: java.<span style="">sql</span>.<span style="">SQLException</span>: <span style="color:#006600; font-weight:bold;">&#91;</span>Macromedia<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer JDBC Driver<span style="color:#006600; font-weight:bold;">&#93;</span>Error establishing socket. <span style="">Connection</span> refused: connect </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>First thing I checked (well second after making sure I had provided the right connection details) was to see if anything was listening port on port 1433 by using the handy "netstats -a" command. And there wasn't, so a quick Google search turned up<a href="http://www.robisen.com/index.cfm?mode=entry&amp;entry=BE1AB594-55DC-F2B1-F392552E0A41542A"> this gem from Robi Sen</a>. Sadly this tool didn't help me as apparently my version didn't need it, but a comment did point me to <a href="http://support.microsoft.com/kb/841251/" title="How to enable SQL Server connectivity on Windows XP Service Pack 2">a another link</a>. But sadly it didn't help me either, but the comment did give me an idea. When I went to check my network set up for MS SQL server, sure enough TCP/IP was not listed... What followed was a moment of banging my head sharply on the table.</p>
<p>Right changes applied, restarted the server, verify connection and...</p>
<div class="igBar"><span id="lcode-8"><a href="#" onclick="javascript:showPlainTxt('code-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-8">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Connection verification failed for data source: SMS</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">java.<span style="">sql</span>.<span style="">SQLException</span>: <span style="color:#006600; font-weight:bold;">&#91;</span>Macromedia<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer JDBC Driver<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer<span style="color:#006600; font-weight:bold;">&#93;</span>Login failed for user <span style="color:#CC0000;">'hermes'</span>. <span style="">Reason</span>: Not associated with a trusted SQL Server connection.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">The</span> root cause was that: java.<span style="">sql</span>.<span style="">SQLException</span>: <span style="color:#006600; font-weight:bold;">&#91;</span>Macromedia<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer JDBC Driver<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>SQLServer<span style="color:#006600; font-weight:bold;">&#93;</span>Login failed for user <span style="color:#CC0000;">'yourUsername'</span>. <span style="">Reason</span>: Not associated with a trusted SQL Server connection. </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Well this one only took a few seconds to fix: <a href="http://www.banmanpro.com/support/sql2k.asp" title="Login Failed for User 'BanManProSQL', Not Associated with a trusted SQL Server Connection.">Windows Authentication only was enabled</a>! Simply open the properties of your server once more, check the security tab and you should see that the option for Windows Authentication is selected. Just change that to SQL server and Windows and you are ready to go...</p>
<p>I guess this is very much a case of damned if you do and damned if you don't for Microsoft as they seemed to have tightened up the security for MS SQL server (I won't even go into the nuisance of trying to install MSDE and being prompted to set an SA password before starting with no indication how to do so), but surely we should be given the option at install time to set these things? Or maybe it's just the MSDE?</p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2005/12/16/cfmx-msde-connection-refused-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updates from a select</title>
		<link>http://gregs.tcias.co.uk/2003/10/20/updates-from-a-select/</link>
		<comments>http://gregs.tcias.co.uk/2003/10/20/updates-from-a-select/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>gregs</dc:creator>
				<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://gregs.tcias.co.uk/?p=432</guid>
		<description><![CDATA[I have been doing a lot more database based work recently and have learned one or two pretty useful techniques. Here is an extremely useful one: Running an update based on a select statement. In the past whenever I could &#8230; <a href="http://gregs.tcias.co.uk/2003/10/20/updates-from-a-select/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been doing a lot more database based work recently and have learned one or two pretty useful techniques. Here is an extremely useful one: Running an update based on a select statement.</p>
<p>In the past whenever I could have wanted to do a bulk update on a table based on certain criteria, I would have run a select statement to retrieve a bunch of columns first and then programmatically looped over the result set and updated the values. But there is a much, much easier and way more efficient way of doing this. Just take a quick look at the statement below.</p>
<div class="igBar"><span id="lcode-10"><a href="#" onclick="javascript:showPlainTxt('code-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-10">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">UPDATE someUsersTable</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">SET someUsersTable.<span style="">EmailPrivate</span> = someOtherJoinTable.<span style="">PublicEmail</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">FROM someUsersTable INNER JOIN someOtherJoinTable ON someUsersTable.<span style="">userID</span> = someOtherJoinTable.<span style="">userID</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">WHERE <span style="color:#006600; font-weight:bold;">&#40;</span>tbl_Users.<span style="">userEmailPrivate</span> = <span style="color:#CC0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It was constructed very much the way I would have normally approached the problem. First I wrote the select statement in Query Analyzer, i.e. <em>SELECT * FROM FROM someUsersTable INNER JOIN someOtherJoinTable ON someUsersTable.userID = someOtherJoinTable.userID WHERE (tbl_Users.userEmailPrivate = '')</em>. This gave me the result set I wanted to work with. Next I quite simply removed the SELECT statement replaced it with a corresponding UPDATE statement. So easy when you know how and the performance should be way better than before hand, because rather than making multiple trips back and forth to the database server from the web application it's all handled by the database server in one swoop!</p>
]]></content:encoded>
			<wfw:commentRss>http://gregs.tcias.co.uk/2003/10/20/updates-from-a-select/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

