<?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>Keyboard Face &#187; SQL Server</title>
	<atom:link href="http://www.keyboardface.com/archives/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.keyboardface.com</link>
	<description>when you find QWERTY imprinted on your cheek - it&#039;s time to go to bed.</description>
	<lastBuildDate>Sat, 03 Dec 2011 17:36:40 +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>Getting PHP and Microsoft SQL Server (MSSQL) to play nice</title>
		<link>http://www.keyboardface.com/archives/2011/08/24/getting-php-and-microsoft-sql-server-mssql-to-play-nice/</link>
		<comments>http://www.keyboardface.com/archives/2011/08/24/getting-php-and-microsoft-sql-server-mssql-to-play-nice/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 17:20:16 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/?p=230</guid>
		<description><![CDATA[I have a Windows Server 2008 with IIS7 installed. I&#8217;ve been pounding my head against a Microsoft constructed brick wall for the past day trying to get PHP to interact with SQL Server 2008. http://www.microsoft.com/download/en/details.aspx?displaylang=en&#038;id=20098 A brief Google search pulls up a download page from Microsoft with the newest SQL Server drivers for PHP: In [...]]]></description>
			<content:encoded><![CDATA[<p>I have a Windows Server 2008 with IIS7 installed. I&#8217;ve been pounding my head against a Microsoft constructed brick wall for the past day trying to get PHP to interact with SQL Server 2008. </p>
<p><a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&#038;id=20098">http://www.microsoft.com/download/en/details.aspx?displaylang=en&#038;id=20098</a></p>
<p>A brief Google search pulls up a download page from Microsoft with the newest SQL Server drivers for PHP:</p>
<p>In the package you download, there are about 9 different files. You only need to install 1 or 2 and there are no instructions as to which one is the one to install. </p>
<p>In my case, even installing ALL of them didn&#8217;t work. My PHPInfo() said there was sql server support, but it wouldn&#8217;t connect to the sql server. </p>
<p>FINALLY, I found a single post that explained it. Turned out my PHP version which was installed by IIS7 was too old! For SqlServer to work &#8211; you have to have PHP 5.2.4 or newer.<br />
The help instructions that come with it aren&#8217;t specific enough.</p>
<p><a href="http://social.msdn.microsoft.com/Forums/en/ssdsgetstarted/thread/5fa1215f-5104-40f3-ac5c-872c4812f416">http://social.msdn.microsoft.com/Forums/en/ssdsgetstarted/thread/5fa1215f-5104-40f3-ac5c-872c4812f416</a></p>
<p>Lastly, here&#8217;s a great link that goes over how to actually use the sqlserver connection. Good god!</p>
<p><a href="http://social.technet.microsoft.com/wiki/contents/articles/whitepaper-accessing-sql-server-databases-from-php.aspx">http://social.technet.microsoft.com/wiki/contents/articles/whitepaper-accessing-sql-server-databases-from-php.aspx</a></p>
<p>One other thing to note if you&#8217;re used to working with .NET or Classic ASP. In PHP the field names are case sensitive. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2011/08/24/getting-php-and-microsoft-sql-server-mssql-to-play-nice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSSQL: Joining another server in a select statment</title>
		<link>http://www.keyboardface.com/archives/2009/04/21/mssql-joining-another-server-in-a-select-statment/</link>
		<comments>http://www.keyboardface.com/archives/2009/04/21/mssql-joining-another-server-in-a-select-statment/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 18:20:23 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/?p=154</guid>
		<description><![CDATA[I&#8217;ve often wondered if I could have a select statement that retrieved data from two databases at a time. I just got a SQL Server tip in the mail this morning that walks you through the steps. It&#8217;s awesome! Does everything and more. The keyword is OPENROWSET. Here&#8217;s the link: http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1353663_mem1,00.html Example from above article: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often wondered if I could have a select statement that retrieved data from two databases at a time. I just got a SQL Server tip in the mail this morning that walks you through the steps. It&#8217;s awesome! Does everything and more. The keyword is OPENROWSET. </p>
<p>Here&#8217;s the link:<br />
<a href="http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1353663_mem1,00.html">http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1353663_mem1,00.html</a></p>
<p>Example from above article:<br />
<code>SELECT e1.EmployeeID, e2.FirstName, e2.LastName, e1.JobTitle<br />
FROM OPENROWSET(<br />
'SQLNCLI',<br />
'Server=SqlSrv1;Trusted_Connection=yes;',<br />
'SELECT EmployeeID, FirstName, LastName, JobTitle<br />
FROM AdventureWorks.HumanResources.vEmployee'<br />
) AS e1<br />
INNER JOIN OPENROWSET(<br />
'Microsoft.Jet.OLEDB.4.0',<br />
'C:\Data\Employees.mdb'; 'admin';' ',<br />
'SELECT EmployeeID, FirstName, LastName, JobTitle<br />
FROM Employees'<br />
) AS e2<br />
ON e1.EmployeeID = e2.EmployeeID<br />
ORDER BY e2.LastName, e2.FirstName</code></p>
<p>Here&#8217;s the MSDN link on OPENROWSET.<br />
<a href="http://msdn.microsoft.com/en-us/library/ms190312.aspx">http://msdn.microsoft.com/en-us/library/ms190312.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2009/04/21/mssql-joining-another-server-in-a-select-statment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSSQL Large Sub Query Impossibility</title>
		<link>http://www.keyboardface.com/archives/2009/01/02/mssql-large-sub-query-impossibility/</link>
		<comments>http://www.keyboardface.com/archives/2009/01/02/mssql-large-sub-query-impossibility/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 21:38:49 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/?p=147</guid>
		<description><![CDATA[I recently had to query to find out how many records from one table were not in another really large table. When you do a select statement like this in MSSQL it overflows and gives you a response of 0. Not very helpful: select count(*) from Table1 where Field Not In (Select Field from Table2) [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to query to find out how many records from one table were not in another really large table. When you do a select statement like this in MSSQL it overflows and gives you a response of 0. Not very helpful: </p>
<p><code>select count(*) from Table1 where Field Not In (Select Field from Table2)</code></p>
<p>All other ideas failing, I finally resorted to writing a query using a temp table variable:<br />
<code>set nocount on;<br />
declare @Tables table (<br />
PK int IDENTITY(1,1),<br />
Field1 varchar(100), Field2 varchar(100)<br />
);<br />
insert into @Tables(Field1 , Field2 )</p>
<p>select t1.Field, t2.Field from Table1 t1<br />
left outer join Table2 t2 on<br />
t1.Field = t2.Field;</p>
<p>set nocount off;<br />
select count(*) as Count, Field1 from @Tables<br />
where Field2 is Null<br />
Group by Field1<br />
Having Count(*) &lt; 2;</code></p>
<p>Talk about complicated! If you have any other better ways of doing this &#8211; please let me know!</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2009/01/02/mssql-large-sub-query-impossibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL String Functions</title>
		<link>http://www.keyboardface.com/archives/2008/04/30/sql-string-functions/</link>
		<comments>http://www.keyboardface.com/archives/2008/04/30/sql-string-functions/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 19:59:16 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2008/04/30/sql-string-functions/</guid>
		<description><![CDATA[Simple-Talk.com came out with a great article titled SQL String User Function Workbench It has some great sql functions that I&#8217;ve spent hours looking for in the past (or had to write myself): Split function SplitLines Within (not from python) EndsWith StartsWith Contains (not from python) Join Parts (not from python) Partition RPartition Anyway, I [...]]]></description>
			<content:encoded><![CDATA[<p>Simple-Talk.com came out with a great article titled <a href="http://www.simple-talk.com/sql/t-sql-programming/sql-string-user-function-workbench-part-2/">SQL String User Function Workbench</a></p>
<p>It has some great sql functions that I&#8217;ve spent hours looking for in the past (or had to write myself):</p>
<ul>
<li>Split function</li>
<li>SplitLines</li>
<li>Within (not from python)</li>
<li>EndsWith</li>
<li>StartsWith</li>
<li>Contains (not from python)</li>
<li>Join</li>
<li>Parts (not from python)</li>
<li>Partition</li>
<li>RPartition</li>
</ul>
<ul>
<p>Anyway, I bookmarked it to go back to in the future. </ul>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2008/04/30/sql-string-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSSQL Table Size for all tables</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/</link>
		<comments>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comments</comments>
		<pubDate>Tue, 12 Jun 2007 21:27:07 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/</guid>
		<description><![CDATA[As far as I could tell there was no easy way to query MSSQL to get a list of all of its tables and their respective sizes. I wrote a sql script that does this for you. It&#8217;s below: declare @RowCount int, @tablename varchar(100) declare @Tables table ( PK int IDENTITY(1,1), tablename varchar(100), processed bit [...]]]></description>
			<content:encoded><![CDATA[<p>As far as I could tell there was no easy way to query MSSQL to get a list of all of its tables and their respective sizes. I wrote a sql script that does this for you. </p>
<p>It&#8217;s below: </p>
<p><code>declare @RowCount int, @tablename varchar(100)<br />
declare @Tables table (<br />
	PK int IDENTITY(1,1),<br />
	tablename varchar(100),<br />
	processed bit<br />
)<br />
INSERT into @Tables (tablename)<br />
	SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME not like 'dt%' order by TABLE_NAME asc</p>
<p>declare @Space table (<br />
	 name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)<br />
)<br />
select top 1 @tablename = tablename from @Tables where processed is null<br />
SET @RowCount = 1<br />
	WHILE (@RowCount &lt;&gt; 0)<br />
		BEGIN<br />
			insert into @Space exec sp_spaceused @tablename<br />
			update @Tables set processed = 1 where tablename = @tablename<br />
			select top 1 @tablename = tablename from @Tables where processed is null<br />
			SET @RowCount = @@RowCount<br />
		END</p>
<p>update @Space set data = replace(data, ' KB', '')<br />
update @Space set data = convert(int, data)/1000<br />
update @Space set data = data + ' MB'<br />
update @Space set reserved = replace(reserved, ' KB', '')<br />
update @Space set reserved = convert(int, reserved)/1000<br />
update @Space set reserved = reserved + ' MB'</p>
<p>select * from @Space order by convert(int, replace(data, ' MB', '')) desc</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>@@Identity Best Practices (MS SQL)</title>
		<link>http://www.keyboardface.com/archives/2006/10/06/identity-mssql/</link>
		<comments>http://www.keyboardface.com/archives/2006/10/06/identity-mssql/#comments</comments>
		<pubDate>Fri, 06 Oct 2006 18:25:12 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2006/10/06/identity-mssql/</guid>
		<description><![CDATA[I just ran across this post that was referenced from an article written on MSDN. For the past 2-3 years I&#8217;ve been working under the idea that @@Identity would return the identity of the most recently added row in the table you were just working with. Not so &#8211; it will give you the identity [...]]]></description>
			<content:encoded><![CDATA[<p>I just ran across <a href="http://weblogs.sqlteam.com/travisl/archive/2003/10/29/405.aspx">this post</a> that was referenced from an article written on MSDN. </p>
<p>For the past 2-3 years I&#8217;ve been working under the idea that @@Identity would return the identity of the most recently added row in the table you were just working with. Not so &#8211; it will give you the identity of the most recently added row in the entire database! I believe, however, that @@identity is limited to working within the connection to the database. For instance, if you have 2 scripts and they both add a row to the database, they would be using separate connections to the database and thus wouldn&#8217;t be confused. If your database uses <a href="http://www.sqlteam.com/item.asp?ItemID=3850">triggers</a> and your trigger adds a row in another table, @@identity will return the identity of <b>that</b> row, not the one you want. </p>
<p>The alternative offered in the article is to use <strong>scope_identity()</strong>. It acts the same way, only without this little idiosyncrasy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2006/10/06/identity-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Choosing MSSQL Data Types</title>
		<link>http://www.keyboardface.com/archives/2006/09/08/choosing-mssql-data-types/</link>
		<comments>http://www.keyboardface.com/archives/2006/09/08/choosing-mssql-data-types/#comments</comments>
		<pubDate>Sat, 09 Sep 2006 05:53:03 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2006/09/08/choosing-mssql-data-types/</guid>
		<description><![CDATA[This may not interest many of you, but I found a great article on designing database tables in Microsoft SQL Server 2000. Before reading, I had a general understanding of all the types, but I didn&#8217;t have any base for choosing which type to use where. You may want to check it out: http://www.mssqlcity.com/Articles/General/choose_data_type.htm]]></description>
			<content:encoded><![CDATA[<p>This may not interest many of you, but I found a great article on designing database tables in Microsoft SQL Server 2000. Before reading, I had a general understanding of all the types, but I didn&#8217;t have any base for choosing which type to use where. </p>
<p>You may want to check it out: </p>
<p><a href="http://www.mssqlcity.com/Articles/General/choose_data_type.htm">http://www.mssqlcity.com/Articles/General/choose_data_type.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2006/09/08/choosing-mssql-data-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intellisense for SQL &#8211; Free</title>
		<link>http://www.keyboardface.com/archives/2006/06/20/intellisense-for-sql-free/</link>
		<comments>http://www.keyboardface.com/archives/2006/06/20/intellisense-for-sql-free/#comments</comments>
		<pubDate>Tue, 20 Jun 2006 16:32:59 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2006/06/20/intellisense-for-sql-free/</guid>
		<description><![CDATA[SQL Prompt is a great program put out by Red Gate. They just released a deal where they are giving it away for free until September 1st 2006 (That&#8217;s when they will release a new version of the product.) I downloaded it and tried it out, and it works great &#8211; very handy to have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.red-gate.com/products/SQL_Prompt/index.htm">SQL Prompt</a> is a great program put out by <a href="http://www.red-gate.com">Red Gate</a>. </p>
<p>They just released a deal where they are giving it away for free until September 1st 2006 (That&#8217;s when they will release a new version of the product.)</p>
<p>I downloaded it and tried it out, and it works great &#8211; very handy to have when you are dealing with tables with lots of fields, etc. It works with Microsoft Query Analyzer, SQL Server 2005 Management Studio, Visual Studio 2005, Visual Studio .NET 2003, SQL Server 2000 Enterprise Manager, UltraEdit32. </p>
<p>I personally tried it out with Microsoft Query Analyzer.</p>
<p>Here&#8217;s the link to the download page: <a href="http://www.red-gate.com/products/SQL_Prompt/index.htm">SQL Prompt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2006/06/20/intellisense-for-sql-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSSQL to MDB</title>
		<link>http://www.keyboardface.com/archives/2006/04/18/mssql-to-mdb/</link>
		<comments>http://www.keyboardface.com/archives/2006/04/18/mssql-to-mdb/#comments</comments>
		<pubDate>Tue, 18 Apr 2006 22:59:43 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2006/04/18/mssql-to-mdb/</guid>
		<description><![CDATA[It&#8217;s fairly easy to take an MDB database and convert it to SQL Server, but how about taking an SQL Server database and downloading it into an MDB file (Microsoft Access)? This article has some code to do just that: http://www.codeproject.com/useritems/SQL_to_Access_Data_Export.asp]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s fairly easy to take an MDB database and convert it to SQL Server, but how about taking an SQL Server database and downloading it into an MDB file (Microsoft Access)? </p>
<p>This article has some code to do just that: <a href="http://www.codeproject.com/useritems/SQL_to_Access_Data_Export.asp">http://www.codeproject.com/useritems/SQL_to_Access_Data_Export.asp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2006/04/18/mssql-to-mdb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update using an inner join (MSSQL)</title>
		<link>http://www.keyboardface.com/archives/2006/04/03/update-using-an-inner-join-mssql/</link>
		<comments>http://www.keyboardface.com/archives/2006/04/03/update-using-an-inner-join-mssql/#comments</comments>
		<pubDate>Tue, 04 Apr 2006 00:36:48 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.keyboardface.com/archives/2006/04/03/update-using-an-inner-join-mssql/</guid>
		<description><![CDATA[Just searched the net trying to figure out how to do an update using an inner join. I figured it was possible, and I was right. Here&#8217;s how to do it: UPDATE Table1 SET Table1.Title = Table2.Title FROM Table1, Table2 where Table1.ID = Table2.ID If you are using aliases &#8211; for instance if you are [...]]]></description>
			<content:encoded><![CDATA[<p>Just searched the net trying to figure out how to do an update using an inner join. I figured it was possible, and I was right. Here&#8217;s how to do it: </p>
<p><code>UPDATE Table1<br />
SET Table1.Title = Table2.Title<br />
FROM Table1, Table2<br />
where Table1.ID = Table2.ID</code></p>
<p>If you are using aliases &#8211; for instance if you are updating a table you are joining to itself, use this code:</p>
<p><code>UPDATE Table1Alias<br />
SET Table1Alias.Title = Table2Alias.Title<br />
FROM Table1 as Table1Alias, Table2 as Table2Alias<br />
where Table1Alias.ID = Table2Alias.ID</code></p>
<p>Another scenario you may encounter is where you want to update a table, but use an inner join to further filter the rows you want to update. </p>
<p>Here&#8217;s an example of how to do this: </p>
<p><code>UPDATE Table1 Set Field1 = Value<br />
FROM Table1 as t1<br />
INNER JOIN Table2 as t2 on t1.Field2 = t2.Field2<br />
WHERE Field3 = Value</code></p>
<p>That seems too simple, but it eluded me for a long time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyboardface.com/archives/2006/04/03/update-using-an-inner-join-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

