<?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>Eric Fickes &#187; tips and tricks</title>
	<atom:link href="http://ericfickes.com/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericfickes.com</link>
	<description>Design minded Internet Programmer</description>
	<lastBuildDate>Fri, 28 Oct 2011 04:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>An aggregate may not appear in the set list of an UPDATE statement</title>
		<link>http://ericfickes.com/2011/02/an-aggregate-may-not-appear-in-the-set-list-of-an-update-statement/</link>
		<comments>http://ericfickes.com/2011/02/an-aggregate-may-not-appear-in-the-set-list-of-an-update-statement/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 06:43:00 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[internets]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1998</guid>
		<description><![CDATA[Ever seen the error &#8220;An aggregate may not appear in the set list of an UPDATE statement&#8221; when working with SQL Server?  I ran into this one recently after trying to put a COUNT in an UPDATE statement.  I was rewriting &#8230; <a href="http://ericfickes.com/2011/02/an-aggregate-may-not-appear-in-the-set-list-of-an-update-statement/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever seen the error &#8220;An aggregate may not appear in the set list of an UPDATE statement&#8221; when working with SQL Server?  I ran into this one recently after trying to put a COUNT in an UPDATE statement.  I was rewriting some legacy code to use a stored procedure, and it turned out to be the perfect case for a <a title="Read about Temporary Tables on MSDN" href="http://msdn.microsoft.com/en-us/library/ms177399.aspx" target="_blank">Temporary Table</a>.</p>
<p>Instead of boring you with a work scenario, let&#8217;s take a simpler one that uses the <a title="Download Microsoft's AdventureWorks database from this site so you can play along at home" href="http://msftdbprodsamples.codeplex.com/releases/view/37109" target="_blank">AdventureWorks</a> database.  This example will create a list of sales people, total order count for each person, and store this list a single table variable to be used as the final data table.</p>
<p>Should be three simple steps right?</p>
<h2>1. Create @Table variable</h2>
<pre class="brush: sql; title: ; notranslate">
DECLARE @SalesPeople TABLE
(
  EmployeeID int NOT NULL,
  SalesPersonID int NOT NULL,
  FullName varchar(200) NOT NULL,
  Title varchar(200) NOT NULL,
  sales_count int NULL default 0
)
</pre>
<h2>2. INSERT sales people into @Table</h2>
<pre class="brush: sql; title: ; notranslate">
-- HACKISH : Match SalesPersonID to EmployeeID, and fill @SalesPeople
INSERT INTO @SalesPeople
( EmployeeID, SalesPersonID, FullName, Title )
SELECT	e.EmployeeID, sp.SalesPersonID,
		c.FirstName + ' ' + c.LastName as FullName,
		e.Title
FROM	Sales.SalesPerson sp,
		HumanResources.Employee e,
		Person.Contact c
WHERE	sp.SalesPersonID = e.EmployeeID
AND		e.ContactID = c.ContactID
</pre>
<h2>3. UPDATE @Table with COUNT</h2>
<pre class="brush: sql; title: ; notranslate">
UPDATE	@SalesPeople
SET
	sales_count = COUNT( soh.SalesOrderID )
FROM	@SalesPeople sp, Sales.SalesOrderHeader soh
WHERE EXISTS (
	SELECT DISTINCT SalesPersonID FROM @SalesPeople WHERE SalesPersonID = soh.SalesPersonID
)
AND	sp.SalesPersonID = soh.SalesPersonID
</pre>
<div id="attachment_2004" class="wp-caption alignnone" style="width: 775px"><a style="font-weight: normal;" href="http://ericfickes.com/wp-content/uploads/2011/02/aggregate-error.png" rel="lightbox[1998]"><img title="aggregate-error" src="http://ericfickes.com/wp-content/uploads/2011/02/aggregate-error.png" alt="" width="765" height="187" /></a><p class="wp-caption-text">Not COUNT allowed in an UPDATE SET statement</p></div>
<p>The third step is where the original error comes in, so let&#8217;s update this to four steps and see how a Table Variable gets through this.</p>
<h2>1 &amp; 2 &#8211; Repeat from above</h2>
<h2>3. Create Table Variable of order counts</h2>
<pre class="brush: sql; title: ; notranslate">
SELECT	soh.SalesPersonID, COUNT( soh.SalesOrderID ) AS sales_count
INTO	#SalesOrderCounts
FROM	Sales.SalesOrderHeader soh
WHERE EXISTS (
	SELECT DISTINCT SalesPersonID FROM @SalesPeople WHERE SalesPersonID = soh.SalesPersonID
)
GROUP BY soh.SalesPersonID
</pre>
<h2>4. Update @Table with order counts</h2>
<pre class="brush: sql; title: ; notranslate">
UPDATE	@SalesPeople
SET		sales_count = tmp.sales_count
FROM	@SalesPeople sp, #SalesOrderCounts tmp
WHERE	sp.SalesPersonID = tmp.SalesPersonID
</pre>
<p>And here&#8217;s the full script from start to finish with the table variable in use.</p>
<pre class="brush: sql; title: ; notranslate">
-- Master table of sales people
DECLARE @SalesPeople TABLE
(
  EmployeeID int NOT NULL,
  SalesPersonID int NOT NULL,
  FullName varchar(200) NOT NULL,
  Title varchar(200) NOT NULL,
  sales_count int NULL default 0
)

-- Match SalesPersonID to EmployeeID, and fill @SalesPeople
INSERT INTO @SalesPeople
( EmployeeID, SalesPersonID, FullName, Title )
SELECT	e.EmployeeID, sp.SalesPersonID,
		c.FirstName + ' ' + c.LastName as FullName,
		e.Title
FROM	Sales.SalesPerson sp, HumanResources.Employee e, Person.Contact c
WHERE	sp.SalesPersonID = e.EmployeeID
AND		e.ContactID = c.ContactID

-- put sales counts into the other kind of #tableVariable
SELECT	soh.SalesPersonID, COUNT( soh.SalesOrderID ) AS sales_count
INTO	#SalesOrderCounts
FROM	Sales.SalesOrderHeader soh
WHERE EXISTS (
	SELECT DISTINCT SalesPersonID FROM @SalesPeople WHERE SalesPersonID = soh.SalesPersonID
)
GROUP BY soh.SalesPersonID

-- Update our master @table with data from #tableVariable
UPDATE	@SalesPeople
SET		sales_count = tmp.sales_count
FROM	@SalesPeople sp, #SalesOrderCounts tmp
WHERE	sp.SalesPersonID = tmp.SalesPersonID

-- dump the results
SELECT	FullName, Title, sales_count
FROM	@SalesPeople

-- cleanup
drop table #SalesOrderCounts
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/02/an-aggregate-may-not-appear-in-the-set-list-of-an-update-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eleven Coldfusion-ish tips from the field</title>
		<link>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/</link>
		<comments>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 08:34:49 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[adobe]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[asc]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[cfscript]]></category>
		<category><![CDATA[chr]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[listcontains]]></category>
		<category><![CDATA[listfind]]></category>
		<category><![CDATA[listhasvalue]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[parameterized query]]></category>
		<category><![CDATA[special character]]></category>
		<category><![CDATA[sproc]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1965</guid>
		<description><![CDATA[I&#8217;ve had this running list of Coldfusion tips on my wall for the last few years and it&#8217;s time to get these online.  All of the items in this list came from Coldfusion projects over the last few years, but &#8230; <a href="http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had this running list of Coldfusion tips on my wall for the last few years and it&#8217;s time to get these online.  All of the items in this list came from Coldfusion projects over the last few years, but a good portion of these could easily be considered tips for server programmers.  I definitely run into the same items when programming Asp.NET.</p>
<p>There is no rhyme or reason here, just some things I felt need to be repeated.</p>
<h2>1. <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_m-r_14.html" target="_blank">PreserveSingleQuotes</a>()</h2>
<p>This one came in really handy on a project requiring large text files to be imported into a MySQL database.  I used Coldfusion to upload and read the files into large INSERT chunks using <a href="http://dev.mysql.com/doc/refman/5.5/en/insert.html" target="_blank">MySQL&#8217;s multi &#8211; row INSERT syntax</a>. Code built the VALUES portion of the SQL, then I just fed the data into a function for insertion.</p>
<pre class="brush: sql; title: ; notranslate">
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
</pre>
<pre class="brush: coldfusion; title: ; notranslate">
	&lt;cfquery name=&quot;insert_data&quot; result=&quot;insert_result&quot; DATASOURCE=&quot;#request.dsn#&quot; USERNAME=&quot;#request.dbuser#&quot; PASSWORD=&quot;#request.dbpswd#&quot;&gt;
	INSERT INTO table
	( column1, column2, column3, column4, column5, column6, column7 )
	VALUES
	#PreserveSingleQuotes( insert_values )#
	&lt;/cfquery&gt;
</pre>
<h2>2. What if GENERATED_KEY doesn&#8217;t work?</h2>
<p>If you&#8217;re using MySQL and the GENERATED_KEY property of your cfquery objects isn&#8217;t populating, you can use <a href="http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id" target="_blank">LAST_INSERT_ID</a> instead.</p>
<pre class="brush: sql; title: ; notranslate">SELECT LAST_INSERT_ID();</pre>
<h2>3. Use ArrayAppend when building strings</h2>
<p>Classic performance tuning tip for just about any programming language.  Here I&#8217;ll give a Coldfusion example and keep it dead simple.  If you ever have to concatenate strings in code, user ArrayAppend instead.  Here are two loops that do the same thing.  If you run this code, you should notice loop1 takes forever, and loop2 is smoking fast.</p>
<p><strong>slow&#8230;..</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
xx				= 100000;
insertString	= &quot;&quot;;

// do the loop
while( xx &gt; 0 ) {
	insertString &amp;= xx &amp; &quot; &quot;;
	xx--;
}

WriteOutput( insertString);
&lt;/cfscript&gt;
</pre>
<p><strong>FAST!</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
xx				= 1000000;
insertArray		= ArrayNew(1);
// do the loop
while( xx &gt; 0 ) {
	ArrayAppend( insertArray, xx &amp; &quot; &quot; );
	xx--;
}

WriteOutput( ArrayToList( insertArray, &quot; &quot; ) );
ArrayClear( insertArray );
&lt;/cfscript&gt;
</pre>
<h2>4. If CSV, then CHR</h2>
<p>This one is simple, if you find yourself creating CSV or any other text file, use special characters when dealing with single and double quotes, etc.</p>
<ul>
<li>chr(9) = Tab</li>
<li>chr(34) = &#8221; double quote</li>
<li>chr(39) = &#8216; single quote</li>
</ul>
<p>And if you&#8217;re not sure of the correct code for the character you&#8217;re looking to use, just wrap that character in <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_a-b_25.html" target="_blank">ASC()</a> and <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ecf.html" target="_blank">WriteOutput</a> to the page.</p>
<h2>5. Use CFMail with GMail</h2>
<p>This is a no brainer, but with how difficult sending email can be with <em><a title="I love .NET, but it's a pain in the butt sometimes" href="http://www.google.com/search?sourceid=chrome&amp;ie=UTF-8&amp;q=send+email+with+ASP.NET" target="_blank">other languages</a></em>, I&#8217;m mentioning it here.</p>
<p><strong>Application.cfc</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
	APPLICATION.mail.server		= &quot;smtp.gmail.com&quot;;
	APPLICATION.mail.port		= &quot;465&quot;;
	APPLICATION.mail.ssl		= true;
	APPLICATION.mail.user		= &quot;gmailAccount&quot;;
	APPLICATION.mail.pswd		= &quot;gmailPasssword&quot;;
&lt;/cfscript&gt;
</pre>
<p><strong>Emailer.cfm</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfmail to=&quot;work@ericfickes.com&quot;
		bcc=&quot;&quot;
		from=&quot;web@master.com&quot;
		subject=&quot;sending mail is easy with Coldfusion&quot;
		server=&quot;#application.mail.server#&quot;
		useSSL=&quot;#application.mail.ssl#&quot;
		port=&quot;#application.mail.port#&quot;
		username=&quot;#application.mail.user#&quot;
		password=&quot;#application.mail.pswd#&quot;&gt;
#emailBody#
&lt;/cfmail&gt;
</pre>
<h2>6. CFSCRIPT doesn&#8217;t know NULL?</h2>
<p>Another tip from the land of importing and exporting data.  While working with query objects in CFScript, for some reason I could never accurately detect for NULL values.  I tried all sorts of detection schemes and ended up just writing a hacky fail safe.  Please, if you have a better suggestion for *easy* NULL detection in CFSCript, add it in the comments below.</p>
<p><strong>utils.cfc</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;!---  Simple value getter with try / catch to get around NULL values
This function originated in a script where we always needed a &quot; &quot; even if
the value from the database was null.
---&gt;
&lt;cffunction name=&quot;qryGetString&quot; access=&quot;public&quot; returntype=&quot;string&quot;&gt;

&lt;cfargument name=&quot;data&quot; type=&quot;string&quot;&gt;

&lt;cftry&gt;
	&lt;cfscript&gt;
	return #data# &amp; &quot; &quot;;
	&lt;/cfscript&gt;

	&lt;cfcatch type=&quot;Any&quot;&gt;
		&lt;cfreturn &quot; &quot;/&gt;
	&lt;/cfcatch&gt;
&lt;/cftry&gt;

&lt;/cffunction&gt;
</pre>
<p><strong>Exporter.cfm</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
// largeish loop
tab = chr(9);
for( xx = 1; xx &lt;= queryObj.RecordCount; xx++ )
{
	// start the row
	this_row = 	utils_cfc.qryGetString( queryObj.FirstName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.MiddleName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.LastName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.Suffix[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.MedicalTitle[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.email[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_phone[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_fax[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_name[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_address1[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_address2[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_city[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_state[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_zipcode[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.hospital_affiliation[xx] ) &amp; tab;

	// do stuff with the data
}
</pre>
<h2>7. How I find list items</h2>
<h2><span style="font-size: 16px; color: #444444; line-height: 24px;">Ever notice the different behavior in the Coldfusion ListFind commands?  I ended up writing my own ListHasValue function in order to find exact pattern matching in a list.  I had a list of role ids in a list, and just couldn&#8217;t get the built in functions to tell me when my id was in the list without also matching on other ids.  This one makes sense when you run some code.</span></h2>
<p>The top of this sample as my custom ListHasValue() command, and the lower half does three simple loops counting from 1 to 100, and using ListFind, ListContains, and ListHasValue for number checking against the same list.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;!---
	Use this to do an exact pattern check for a value in a list.
	This is useful inside of a loop checking numbers against a number list.

	EX :

	list = &quot;91, 92&quot;

	if you loop from 1 - 100, ListFind and related CF functions will match
	on 1, 2, and 9.  Not just 91 and 92

	Use this when you're looping and you ONLY want to match on 91, or 92

---&gt;
&lt;cffunction name=&quot;ListHasValue&quot; access=&quot;public&quot; returntype=&quot;boolean&quot;&gt;

	&lt;cfargument name=&quot;list&quot; required=&quot;yes&quot; type=&quot;string&quot;&gt;
	&lt;cfargument name=&quot;value&quot; required=&quot;yes&quot; type=&quot;any&quot;&gt;

	&lt;cfscript&gt;
		// clean up to be safe
		list = trim( toString( list ) );

		// check to see if we have a *possible* match
		position = ListContains( list, value ) ;

		if( position &gt; 0 )
		{
			// NOTE : KEEP THE TRIM AND TOSTRING
			found_value = trim( toString( ListGetAt( list, position ) ) );

			if( Compare( value, found_value ) == 0 )
			{
				return true;
			}
		}

		// no match for you!
		return false;
	&lt;/cfscript&gt;

&lt;/cffunction&gt;

&lt;cfscript&gt;
list	= &quot;1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 99&quot;;
xx		= 1;

WriteOutput( &quot;List = &quot; &amp; list &amp; &quot;&lt;hr&gt;&quot;);

while( xx &lt; 100 ) {
	if( ListContains( list, xx ) &gt; 0 )
	{
		WriteOutput( &quot;ListContains found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
    xx++;
}

WriteOutput(&quot;&lt;hr /&gt;&quot;);

xx = 1;
while( xx &lt; 100 ) {
	// ListFind
	if( ListFind( list, xx ) &gt; 0 )
	{
		WriteOutput( &quot;ListFind found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
    xx++;
}

WriteOutput(&quot;&lt;hr /&gt;&quot;);

xx = 1;
while( xx &lt; 100 ) {
    // Eric's ListHasValue
	if( ListHasValue( list, xx ) )
	{
		WriteOutput( &quot;ListHasValue found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
	xx++;
}
&lt;/cfscript&gt;
</pre>
<p>If you run this code on your Coldfusion server, you should notice the following results.  ListContains matches single digits from the loop that do not really exist in the list.  ListFind only finds the number 1?  And finally, my function does exactly what I needed it to do.  Tell me when a specific number exists in a list.</p>
<div id="attachment_1980" class="wp-caption alignnone" style="width: 240px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/cf-list-find1.png" rel="lightbox[1965]"><img class="size-full wp-image-1980" title="cf-list-find" src="http://ericfickes.com/wp-content/uploads/2011/02/cf-list-find1.png" alt="CF ListFind function comparison" width="230" height="559" /></a><p class="wp-caption-text">Coldfusion ListFind functions don&#39;t always behave how I want them to</p></div>
<p><span style="font-size: 16px; color: #444444; line-height: 24px;"><br />
</span></p>
<h2>8. Make PDFs faster</h2>
<p>This could easily be it&#8217;s own topic, but I&#8217;ll say one thing about making PDFs faster with CFDocument.  Only put final content between &lt;cfdocument&gt; and &lt;/cfdocument&gt;.  That is, if you have any processing code, cfqueries, cfloops, inside of your cfdocument tag, your cfml page is running slower than it needs to be.  Here&#8217;s a simple example of one of my cfml pages that has only final content in the cfdocument tags.</p>
<p>The key to this example is moving all of my content creation code into an external file, then including at the top of my page. I always do a check for my main PDF_BODY variable, and then spit out my PDF document.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfinclude template=&quot;code/export_pdf_codefile.cfm&quot;&gt;

&lt;cfif PDF_BODY NEQ &quot;&quot;&gt;

    &lt;cfdocument	name=&quot;provider_profile&quot;
                format=&quot;PDF&quot;
                pagetype=&quot;A4&quot;
                mimetype=&quot;application/pdf&quot;
                orientation=&quot;portrait&quot;
                margintop=&quot;0&quot;
                marginbottom=&quot;0.2&quot;
                marginleft=&quot;0.2&quot;
                marginright=&quot;0.2&quot;
                &gt;
        &lt;cfoutput&gt;#PDF_BODY#&lt;/cfoutput&gt;
    &lt;/cfdocument&gt;

    &lt;!--- send directly to client ---&gt;
    &lt;cfheader name=&quot;Content-Disposition&quot; value=&quot;attachment; filename=#filename#&quot;&gt;
    &lt;cfcontent type=&quot;application/pdf&quot; variable=&quot;#provider_profile#&quot;&gt;

&lt;cfelse&gt;
	No PDF content found
&lt;/cfif&gt;
</pre>
<h2>9. Use parameterized queries</h2>
<p>This is a tip for all server side programmers whether you use Coldfusion, ASP, JSP, PBJ.  Use parameterized queries when doing any database interaction.  It&#8217;s too easy not to use, and you get protection from SQL Injection, as well as enforcing proper data types when speaking to your database.  This is something all server programmers should do regardless of your language, the sample below is for Coldfusion.</p>
<p><strong>BAD</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfquery name=&quot;tblInsert&quot; datasource=&quot;myDb&quot;&gt;
INSERT INTO	myTable
( col1, col2, col3, col4 )
VALUES
( '#Form.field1#', '#Form.field2#', '#Form.field3#' )
&lt;/cfquery&gt;
</pre>
<p><strong>GOOD</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfset val1 = Form.field1&gt;
&lt;cfset val2 = Form.field1&gt;
&lt;cfset val3 = Form.field1&gt;

&lt;cfquery name=&quot;tblInsert&quot; datasource=&quot;myDb&quot;&gt;
INSERT INTO	myTable
( col1, col2, col3, col4 )
VALUES
(
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val1#&quot; /&gt;,
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val2#&quot; /&gt;,
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val3#&quot; /&gt;
)
&lt;/cfquery&gt;
</pre>
<h2>10. Where&#8217;d the time go?</h2>
<p>For the good programmers already using parameterized queries, ever insert a timestamp into your database and find out the date is correct, but the time is always 12:00:00?  Take a closer look at the cfsqltype in your cfqueryparam, I had this exact problem and here&#8217;s what happened.</p>
<p>Using <strong>cf_sql_date does</strong> not include the full date and timestamp, just the date.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfqueryparam cfsqltype=&quot;cf_sql_date&quot; value=&quot;#paymentDate#&quot; /&gt;
</pre>
<p>&nbsp;</p>
<p>Using <strong>cf_sql_timestamp</strong> includes the full date and timestamp I was looking for.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfqueryparam cfsqltype=&quot;cf_sql_timestamp&quot; value=&quot;#paymentDate#&quot; /&gt;
</pre>
<h2>11. Stored Procedures are a little different</h2>
<p>This last one isn&#8217;t much of a tip, but more of a reminder to myself.  I do so much database work that stored procedures are just queries to me, but not so to Coldfusion and the CFQuery tag.  If you want to get data from a stored procedure, you need to use the <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_r-s_22.html" target="_blank">CFStoredproc</a> tag.  Here&#8217;s a sample of passing one argument into a stored procedure, and how to get the resulting data.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfstoredproc	datasource=&quot;myDb&quot; procedure=&quot;GetDataFaster&quot;&gt;

	&lt;cfprocparam type=&quot;in&quot; cfsqltype=&quot;cf_sql_integer&quot; value=&quot;#inputVar#&quot; /&gt;

	&lt;!--- specify sproc result here, cfstoredproc res != returned recordset ---&gt;
	&lt;cfprocresult name = sprocResult&gt;

&lt;/cfstoredproc&gt;

&lt;cfreturn #sprocResult.ColumnFromQuery#&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Injecting javascript into asp.net via code</title>
		<link>http://ericfickes.com/2011/02/injecting-javascript-into-asp-net-via-code/</link>
		<comments>http://ericfickes.com/2011/02/injecting-javascript-into-asp-net-via-code/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 04:13:50 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Literal]]></category>
		<category><![CDATA[msdn]]></category>
		<category><![CDATA[postback]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1903</guid>
		<description><![CDATA[Microsoft has a great MSDN article on using javascript along asp.net, but they didn&#8217;t mention a technique I like to use, put it in a Literal control.  While there are many ways to add javascript to a page, I find &#8230; <a href="http://ericfickes.com/2011/02/injecting-javascript-into-asp-net-via-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Microsoft has a great MSDN article on <a title="Several other techniques for using javascript with asp.net" href="http://msdn.microsoft.com/en-us/library/aa479011.aspx" target="_blank">using javascript along asp.net</a>, but they didn&#8217;t mention a technique I like to use, put it in a <a title="ASP.NET Literal Class" href="http://msdn.microsoft.com/en-us/library/f0aw4d5w.aspx" target="_blank">Literal</a> control.  While there are many ways to add javascript to a page, I find putting the javascript in a literal much less stressful.  Using a Literal control placeholder is also a good way to add messaging to a page after postback, but we&#8217;re just going to look at adding javascript.</p>
<p>Let&#8217;s take a simple example.  Say you&#8217;ve got a comment form that you want to auto close, or reload after the form was posted.  Below is a simple single file style asp.net page with a simple javascript function that reloads this page.</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;%@ Page Language=&quot;C#&quot; %&gt;

&lt;script runat=&quot;server&quot;&gt;
/// &lt;summary&gt;
/// &lt;/summary&gt;
/// &lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {

    }
}

///////////////////////////////////////////////////////////////////////////////
/// Do stuff with the form data, then refresh page using javascript
protected void submitComments(object sender, EventArgs e)
{

    try
    {
	//
	// do stuff here
	//

	// set javascript timer to reload page afer 3 seconds
	js_target.Text = &quot;setTimeout('reload()', 3000);&quot;;

    }
    catch (Exception exc)
    {
        Response.Write( &quot;ERROR : &quot; + exc.Message );
    }
}
&lt;/script&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head&gt;
	&lt;title&gt;Comments&lt;/title&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	// page reload helper
	function reload() {
		document.location.replace( document.location );
	}
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form id=&quot;form1&quot; runat=&quot;server&quot; method=&quot;post&quot;&gt;

&lt;script type=&quot;text/javascript&quot;&gt;&lt;asp:Literal runat=&quot;server&quot; id=&quot;js_target&quot; /&gt;&lt;/script&gt;

	Comments
	&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;comment_box&quot; Width=&quot;200&quot; /&gt;
	&lt;br&gt;&lt;br&gt;

	Your name
	&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;fullname&quot; Width=&quot;200&quot; /&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;asp:Button runat=&quot;server&quot; ID=&quot;submit_btn&quot; onclick=&quot;submitComment&quot; Text=&quot;submit&quot; /&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you look just under the form tag you&#8217;ll see the key to this technique, an asp literal wrapped by an open and close script tag.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;&lt;asp:Literal runat=&quot;server&quot; id=&quot;js_target&quot; /&gt;&lt;/script&gt;
</pre>
<p>When you load your page and view the source you&#8217;ll just see an empty script tag, so it shouldn&#8217;t interfere with the execution or rendering of your page.</p>
<p>The last part of this technique is simple, in your server code just set your Literal control&#8217;s .Text value to your javascript code.  In this case when I post my comment form, after handling the input data I display a thank you message, then set some javascript to reload the page.</p>
<pre class="brush: csharp; title: ; notranslate">
ltl_js.Text = &quot;setTimeout('reload()', 3000);&quot;;
</pre>
<p>That&#8217;s all there is to it.  Drop a literal in an empty script block and BAM!, you have an easy way to add javascript to your asp.net page.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/02/injecting-javascript-into-asp-net-via-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Today I took 30 minutes to save hours</title>
		<link>http://ericfickes.com/2011/01/today-i-took-30-minutes-to-save-hours/</link>
		<comments>http://ericfickes.com/2011/01/today-i-took-30-minutes-to-save-hours/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 04:21:41 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[batch file]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[DECLARE]]></category>
		<category><![CDATA[del]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[fetch]]></category>
		<category><![CDATA[fetch_status]]></category>
		<category><![CDATA[information_schema]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[sproc]]></category>
		<category><![CDATA[sqlcmd]]></category>
		<category><![CDATA[sys]]></category>
		<category><![CDATA[tsql]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1861</guid>
		<description><![CDATA[UPDATE &#8211; 1/6/2011 : Since writing this post I have bundled this entire reset process into a single windows batch file. In addition to restoring my database, I also have to remove temp files from my server, so it was &#8230; <a href="http://ericfickes.com/2011/01/today-i-took-30-minutes-to-save-hours/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong> </strong><strong>UPDATE &#8211; </strong><strong>1/6/2011 : </strong>Since writing this post I have bundled this entire reset process into a single <a title="How to use windows batch files" href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true" target="_blank">windows batch file</a>. In addition to restoring my database, I also have to remove temp files from my server, so it was time to go command line with all of this.</p>
<p>Here the contents of my batch file.</p>
<pre class="brush: plain; title: ; notranslate">
### DELETE TEMP FILES
del /q /f /s Z:\_FavoriteClient\_GIT_\webapp\invoices\* /f /s

### RESTORE DATABASE
sqlcmd -S &quot;localhost&quot; -i Z:\_FavoriteClient\_GIT_\sql\restoreBackup.sql
</pre>
<p>To use this in a .bat file, copy and paste the text into Notepad, then save as &#8220;restore.bat&#8221;.  Remember, you will need to wrap your filename.bat with quotes, otherwise Notepad will save the file as filename.bat.txt.</p>
<p>* The contents of restoreBackup.sql is listed below.</p>
<hr style="color: efefef;" size="1" noshade="noshade" />One of my favorite pastimes as a programmer is writing code that writes code, aka workflow automation.  It&#8217;s not something I do on every project, but I&#8217;ve been doing a lot of SQL Server development recently, and I&#8217;ve been having a lot of fun using the <a title="SQL 2008 RS Information Schema Views (Transact-SQL)" href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target="_blank">INFORMATION_SCHEMA views</a> to <a title="Use TSQL to generate Actionscript VO classes" href="http://ericfickes.posterous.com/tsql-sproc-generatetablevoclass" target="_blank">build VO classes</a>, forms representing tables, or just finding what tables have a specific column.  Today I took a 30 minute trip to the <a title="SQL 2008 SYS tables" href="http://msdn.microsoft.com/en-us/library/ms187406.aspx" target="_blank">SYS side</a> and wrote a tsql script that will save me hours.</p>
<p>The web application I&#8217;m working on is a payment processor made up of five steps.  In order to test I have to setup multiple sales for multiple clients, then log in as three different admin users to push the transactions through the system.  This gets my test transactions to the proper testable state.  The process of setting up testable transactions takes over 30 clicks, and once I hit step 3 of the wizard, my test transactions are completed in a way that I have to re-setup the test data ( 20 GOTO 10 ).</p>
<p>I thought about a handful of options, and ended up going with this solution.</p>
<ol>
<li>Setup all test transactions in web application by hand ( get the data ready )</li>
<li>Take a full database backup ( freeze the data )</li>
<li>Use TSQL script to drop all connections to my app&#8217;s db, then restore the database to the &#8220;testable&#8221; state from step 1 ( reset the DB )</li>
</ol>
<p>Here is my TSQL script</p>
<pre class="brush: sql; title: ; notranslate">
DECLARE @sessID int,
		@dbName varchar(50),
		@userName varchar(50),
		@backupFile varchar(200)

SET @dbName		= 'DA413'	-- your database name
SET @userName	= 'DA413'	-- sql user account to look for
SET @backupFile = 'D:\DB\Backup\DA413.bak' -- path to SQL backup file

-- use a cursor to store all session_ids
DECLARE session_cursor CURSOR
FOR
	SELECT	session_id
	FROM	sys.dm_exec_sessions
	WHERE	original_login_name = @userName

	-- open cursor and grab first row
	OPEN session_cursor
	FETCH NEXT FROM session_cursor INTO @sessID

	-- loop through session_ids
	WHILE @@FETCH_STATUS = 0
	BEGIN

		-- kill it
		-- using EXEC because the sproc kill does not like @variables
		EXEC('kill ' + @sessID)

		-- get the next session_id
		FETCH NEXT FROM session_cursor INTO @sessID
	END

-- cursor cleanup
CLOSE session_cursor
DEALLOCATE session_cursor

-- restore backup
USE master
	RESTORE DATABASE DA413
	FROM DISK = @backupFile
GO
</pre>
<p>A few notes about this script :</p>
<ul>
<li>I only need to disconnect my web application&#8217;s database user, not any user</li>
<li>I&#8217;m using the latest full backup, and not a specific database snapshot</li>
<li>The SPROC <a title="TSQL KILL sproc" href="http://technet.microsoft.com/en-us/library/ms173730.aspx" target="_blank">kill</a> doesn&#8217;t like @variables as input, so use <a title="TSQL EXEC" href="http://msdn.microsoft.com/en-us/library/ms188332.aspx" target="_blank">EXEC</a></li>
<li>Your web server doesn&#8217;t know the user was disconnected, so you&#8217;ll have to log back into your application.</li>
<li>If you use this technique, be sure to RERUN your backup if you add anything to the database ( EX : new table column, stored procedure, etc )</li>
<li>If you&#8217;re not the only person connected to this database, make sure you don&#8217;t disconnect anybody else using the same database name</li>
</ul>
<p>This solution is perfect for me because I have full control over my code, database, and server.  It&#8217;s also great because I can test my application, run a single sql script, and 10 seconds later I can test my application again.  While this solution is perfect for me, it&#8217;s probably best used as reference for others.  However, this technique of rolling back the database could be applied to <em>any</em> software application using SQL Server for it&#8217;s datasource.</p>
<p>Hope this helps somebody.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/01/today-i-took-30-minutes-to-save-hours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PayPal test credit card numbers</title>
		<link>http://ericfickes.com/2010/12/paypal-test-credit-card-numbers/</link>
		<comments>http://ericfickes.com/2010/12/paypal-test-credit-card-numbers/#comments</comments>
		<pubDate>Tue, 28 Dec 2010 17:49:56 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[internets]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[credit card]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://ericfickes.posterous.com/paypal-test-credit-card-numbers</guid>
		<description><![CDATA[Test Credit Card Account Numbers While testing, use only the credit card numbers listed here. Other numbers produce an error. Expiration Date must be a valid date in the future (use the mmyy format). Test Credit Card Account Numbers Credit Card &#8230; <a href="http://ericfickes.com/2010/12/paypal-test-credit-card-numbers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--[CDATA[</p>
<div style="font-family: Arial; font-size: medium;" mce_style="font-family: Arial; font-size: medium;"-->
<h1 style="color: #800000; font-family: Arial, sans-serif; font-size: 16pt; line-height: 18pt; font-weight: bold; font-style: normal; border-bottom-style: solid; margin-bottom: 16pt; margin-right: 1pt; border-bottom-width: 1px;">Test Credit Card Account Numbers</h1>
<p style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">While testing, use only the credit card numbers listed here. Other numbers produce an error.</p>
<p style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;"><span style="font-weight: bold;"><strong>Expiration Date</strong></span></p>
<p>must be a valid date in the future (use the <span style="font-weight: bold;"><strong>mmyy</strong></span> format).</p>
<h2 style="color: #800000; font-size: 14pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 16pt; font-weight: bold; font-style: normal;">Test Credit Card Account Numbers</h2>
<table class="whs1" style="border-collapse: separate;" border="1">
<tbody>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt; font-weight: bold;">Credit Card Type</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt; font-weight: bold;">Credit Card Number</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">American Express</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">378282246310005</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">American Express</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">371449635398431</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">American Express Corporate</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">378734493671000</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Australian BankCard</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">5610591081018250</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Diners Club</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">30569309025904</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Diners Club</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">38520000023237</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Discover</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">6011111111111117</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Discover</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">6011000990139424</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">JCB</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">3530111333300000</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">JCB</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">3566002020360505</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">MasterCard</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">5555555555554444</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">MasterCard</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">5105105105105100</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Visa</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">4111111111111111</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Visa</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">4012888888881881</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Visa</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">4222222222222</p>
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;"><em><span style="font-style: normal; font-weight: bold;"><strong>Note</strong></span></em><strong> :</strong> Even though this number has a different character count than the other test numbers, it is the correct and functional number.</p>
</td>
</tr>
<tr>
<td class="whs6" colspan="2">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Processor-specific Cards</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Dankort (PBS)</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">76009244561</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Dankort (PBS)</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">5019717010103742</p>
</td>
</tr>
<tr>
<td class="whs4" width="248px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">Switch/Solo (Paymentech)</p>
</td>
<td class="whs5" width="363px">
<p class="CellBody" style="margin-top: 1pt; font-size: 10pt; font-family: Arial, sans-serif; margin-bottom: 6pt; line-height: 13pt; margin-right: 1pt;">6331101999990016</p>
</td>
</tr>
</tbody>
</table>
<div><span style="font-family: Arial; font-size: medium;">** This information is a rebroadcast of </span><a href="http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm">http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm</a></div>
<p><a href="http://ericfickes.posterous.com/paypal-test-credit-card-numbers">Permalink</a></p>
<p>| <a href="http://ericfickes.posterous.com/paypal-test-credit-card-numbers#comment">Leave a comment</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/12/paypal-test-credit-card-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get windows on VMWare to see your windows network</title>
		<link>http://ericfickes.com/2010/12/how-to-get-windows-on-vmware-to-see-your-windows-network/</link>
		<comments>http://ericfickes.com/2010/12/how-to-get-windows-on-vmware-to-see-your-windows-network/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 20:00:53 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://ericfickes.posterous.com/how-to-get-windows-on-vmware-to-see-your-wind</guid>
		<description><![CDATA[Set network connection to bridged. Permalink &#124; Leave a comment]]></description>
			<content:encoded><![CDATA[<p><!--[CDATA[</p>
<p--> Set network connection to bridged.</p>
<div><a href="http://posterous.com/getfile/files.posterous.com/ericfickes/J9IeKJe5I41hHE5AocZKDygx0rKF413VdXWRAiClumGwI9O5exobldHATuG3/vmware-bridged-network.png" rel="lightbox[2021]"><img src="http://posterous.com/getfile/files.posterous.com/ericfickes/8gKoisMArKtd4M7mtUR8XALhjzJocpiQPzdq7lYAWyKH8GoHdggJ3yGGsLbB/vmware-bridged-network.png.scaled.500.jpg" alt="" width="500" height="368" /></a></div>
<p><a href="http://ericfickes.posterous.com/how-to-get-windows-on-vmware-to-see-your-wind">Permalink</a></p>
<p>| <a href="http://ericfickes.posterous.com/how-to-get-windows-on-vmware-to-see-your-wind#comment">Leave a comment</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/12/how-to-get-windows-on-vmware-to-see-your-windows-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TSQL : How to find all database tables ending with an UPPERCASE X</title>
		<link>http://ericfickes.com/2010/12/tsql-how-to-find-all-database-tables-ending-with-an-uppercase-x/</link>
		<comments>http://ericfickes.com/2010/12/tsql-how-to-find-all-database-tables-ending-with-an-uppercase-x/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:28:59 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[internets]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://ericfickes.posterous.com/tsql-how-to-find-all-database-tables-ending-w</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 -- Give me all tables ending with an UPPERCASE X SELECT table_name, SUBSTRING( table_name, LEN(table_name), 1 ) as &#39;end&#39; FROM INFORMATION_SCHEMA.TABLES -- SELECT ascii(&#39;X&#39;) = 88 -- SELECT ascii(&#39;x&#39;) = &#8230; <a href="http://ericfickes.com/2010/12/tsql-how-to-find-all-database-tables-ending-with-an-uppercase-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><![CDATA[
<div class="data type-sql">
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
</pre>
</td>
<td width="100%">
<div class="highlight">
<pre />
<div class="line" id="LC1"><span class="c1">-- Give me all tables ending with an UPPERCASE X</span></div>
<div class="line" id="LC2"></div>
<div class="line" id="LC3"><span class="k">SELECT</span>	<span class="k">table_name</span><span class="p">,</span> <span class="k">SUBSTRING</span><span class="p">(</span> <span class="k">table_name</span><span class="p">,</span> <span class="n">LEN</span><span class="p">(</span><span class="k">table_name</span><span class="p">),</span> <span class="mi">1</span> <span class="p">)</span> <span class="k">as</span> <span class="s1">&#39;end&#39;</span></div>
<div class="line" id="LC4"></div>
<div class="line" id="LC5"><span class="k">FROM</span>	<span class="n">INFORMATION_SCHEMA</span><span class="p">.</span><span class="n">TABLES</span></div>
<div class="line" id="LC6"></div>
<div class="line" id="LC7"><span class="c1">-- SELECT ascii(&#39;X&#39;) = 88</span></div>
<div class="line" id="LC8"><span class="c1">-- SELECT ascii(&#39;x&#39;) = 120</span></div>
<div class="line" id="LC9"><span class="k">WHERE</span>	<span class="n">ASCII</span><span class="p">(</span> <span class="k">SUBSTRING</span><span class="p">(</span> <span class="k">table_name</span><span class="p">,</span> <span class="n">LEN</span><span class="p">(</span><span class="k">table_name</span><span class="p">),</span> <span class="mi">1</span> <span class="p">)</span> <span class="p">)</span> <span class="o">=</span> <span class="mi">88</span></div>
<div class="line" id="LC10"></div>
</pre>
</div>
</td>
</tr>
</table></div>
</p>
<p><a href="http://ericfickes.posterous.com/tsql-how-to-find-all-database-tables-ending-w">Permalink</a> </p>
<p>	| <a href="http://ericfickes.posterous.com/tsql-how-to-find-all-database-tables-ending-w#comment">Leave a comment</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/12/tsql-how-to-find-all-database-tables-ending-with-an-uppercase-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting random ids using TOP and a CTE</title>
		<link>http://ericfickes.com/2010/09/selecting-random-ids-using-top-and-a-cte/</link>
		<comments>http://ericfickes.com/2010/09/selecting-random-ids-using-top-and-a-cte/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 05:43:49 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[tsql]]></category>
		<category><![CDATA[common table expression]]></category>
		<category><![CDATA[cte]]></category>
		<category><![CDATA[mssqlserver]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[SQLSERVER]]></category>
		<category><![CDATA[top]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1675</guid>
		<description><![CDATA[While testing visualizations in a Flex application, I needed to do some underlying data cleanup in SQL Server.  One of my tasks was to manually update an entity table and set the status column to one of three possibilities.  Status &#8230; <a href="http://ericfickes.com/2010/09/selecting-random-ids-using-top-and-a-cte/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While testing visualizations in a Flex application, I needed to do some underlying data cleanup in SQL Server.  One of my tasks was to manually update an entity table and set the status column to one of three possibilities.  Status group A and B both needed to be roughly 20% of my tables total record count, and status group C would be the remaining rows that weren&#8217;t touched by status A or status B.  Oh and there&#8217;s one more thing, the ids in each status group can not be in sequential order, they have to be random.</p>
<p>At first I thought no sweat.  My dataset is still small ( only 2000 rows ), so if we want uber control I could do the math and generate my id lists by hand.  Yes, hand crafting is possible and under a deadline that kind of logic almost makes sense.  However, I already know the table I&#8217;m working with will grow in the future, and I&#8217;ll probably have to do this data update again, so why not do this right?  While playing around with different select statements I had a &#8220;EUREKA!&#8221; moment.  <a title="TSQL's TOP operator on MSDN" href="http://msdn.microsoft.com/en-us/library/ms189463.aspx" target="_blank">SQL Server&#8217;s TOP operator</a> supports PERCENT, not just number.  I couldn&#8217;t believe it.  I use TOP at least once a week and I always forget about TOP PERCENT.  Since I already know how to select random rows via <a title="SQL Server's Common Table Expressions are super helpful" href="http://msdn.microsoft.com/en-us/library/ms190766.aspx" target="_blank">CTE</a>, it  was time to put it all together.</p>
<p>Before giving you the final SQL, here are the important parts to be familiar with.  Also, for the sake of example I&#8217;m using the <a title="Download the AdventureWorks database from Codeplex" href="http://msftdbprodsamples.codeplex.com/releases/view/37109" target="_blank">AdventureWorks database</a> so you can play along at home.</p>
<h2><a title="MSSQL's TOP operator on MSDN" href="http://msdn.microsoft.com/en-us/library/ms189463.aspx" target="_blank">TOP PERCENT</a></h2>
<p>If you just need 50% of the rows in a table, but you&#8217;re not concerned about the sequence returned, you can fire this query.  This will give you a sequential listing of ProductIDs</p>
<pre class="brush: sql; title: ; notranslate">
SELECT TOP 50 PERCENT ProductID
FROM Production.Product
ORDER BY ProductID
</pre>
<p>Which will look something like this.</p>
<p><a href="http://ericfickes.com/wp-content/uploads/2010/09/SELECT-TOP-20-PERCENT.png" rel="lightbox[1675]"><img class="aligncenter size-full wp-image-1682" title="SELECT TOP 20 PERCENT" src="http://ericfickes.com/wp-content/uploads/2010/09/SELECT-TOP-20-PERCENT.png" alt="SQL's TOP operator returns rows sequentially" width="274" height="255" /></a></p>
<h2><a title="A Common Table Expression can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query..." href="http://msdn.microsoft.com/en-us/library/ms190766.aspx" target="_blank">COMMON TABLE EXPRESSION</a></h2>
<p>Now let&#8217;s say you want to randomly pull all rows from a table.  This can be achieved using this CTE.</p>
<pre class="brush: sql; title: ; notranslate">
WITH data( ProductID ) AS (
	SELECT	ProductID
	FROM	Production.Product
)
SELECT	ProductID
FROM	data
ORDER BY NEWID()
</pre>
<p>Which will look like this</p>
<p><a href="http://ericfickes.com/wp-content/uploads/2010/09/SELECT-RANDOM-CTE.png" rel="lightbox[1675]"><img class="aligncenter size-full wp-image-1689" title="SELECT RANDOM DATA using CTE" src="http://ericfickes.com/wp-content/uploads/2010/09/SELECT-RANDOM-CTE.png" alt="Common Table Expressions in SQLSERVER are super helpful" width="271" height="381" /></a></p>
<p>If you&#8217;re looking to <a title="Select random value from preset list - tSQL, CTE" href="http://ericfickes.posterous.com/tsql-select-a-random-value-using-cte" target="_blank">randomly select values from a pre-determined list, see my CTE sample here</a>.</p>
<p>So now that you&#8217;ve seen TOP PERCENT and CTE in action, it&#8217;s time to put these together and solve my initial task of creating randomly selected groups of ids, of a percent size.</p>
<p>RANDOMLY SELECT TOP PERCENT</p>
<p>Putting it all together, here is the query I used to create my first status group.</p>
<pre class="brush: sql; title: ; notranslate">
WITH data( ProductID ) AS (
	SELECT	ProductID
	FROM	Production.Product
)
SELECT TOP 20 PERCENT ProductID
FROM	data
ORDER BY NEWID()
</pre>
<p>Which gives me a dataset that is 20% of all rows in Production.Product, and the ids are in random order.</p>
<p>And there you have it.  Randomly selecting a percent sized data set from a table in SQL Server.  The SQL here is really pretty simple, but for some reason I always forget TOP PERCENT.  I&#8217;m hoping this post will help me remember TOP PERCENT, and maybe even help somebody else with some TSQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/09/selecting-random-ids-using-top-and-a-cte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to show line numbers in Visual Studio 2010</title>
		<link>http://ericfickes.com/2010/08/how-to-show-line-numbers-in-visual-studio-2010/</link>
		<comments>http://ericfickes.com/2010/08/how-to-show-line-numbers-in-visual-studio-2010/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 19:11:35 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[line numbers]]></category>
		<category><![CDATA[text editor]]></category>
		<category><![CDATA[visual studio options]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1614</guid>
		<description><![CDATA[I&#8217;ve been using Visual Studio since forever, yet it always takes me a while to remember how to show line numbers.  It&#8217;s especially hard to remember after a fresh install of Visual Studio.  Assuming you have it installed and open, &#8230; <a href="http://ericfickes.com/2010/08/how-to-show-line-numbers-in-visual-studio-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Visual Studio since forever, yet it always takes me a while to remember how to show line numbers.  It&#8217;s especially hard to remember after a fresh install of Visual Studio.  Assuming you have it installed and open, here&#8217;s how to display line numbers in your code.</p>
<ol>
<li>Click Tools in the menu bar</li>
<li>Options</li>
<li>Expand Text Editor ( in the popup window )</li>
<li>Click &#8216;All Languages&#8217;</li>
<li>Check the &#8216;Line numbers&#8217; box under the Display heading ( on the right )</li>
<li>Click OK</li>
<li>Happy Happy Joy Joy!</li>
</ol>
<p><a href="http://ericfickes.com/wp-content/uploads/2010/08/show-line-number-visual-studio-2010.png" rel="lightbox[1614]"><img class="aligncenter size-full wp-image-1615" title="Display Line numbers in Visual Studio 2010" src="http://ericfickes.com/wp-content/uploads/2010/08/show-line-number-visual-studio-2010.png" alt="How to Display Line numbers in Visual Studio 2010" width="784" height="848" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/08/how-to-show-line-numbers-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How I removed iOS4 from my iPhone 3G</title>
		<link>http://ericfickes.com/2010/07/how-i-removed-ios4-from-my-iphone-3g/</link>
		<comments>http://ericfickes.com/2010/07/how-i-removed-ios4-from-my-iphone-3g/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 05:11:57 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[hack]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[downgrade]]></category>
		<category><![CDATA[iOS4]]></category>
		<category><![CDATA[iPhone 3G]]></category>
		<category><![CDATA[iTunes]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1554</guid>
		<description><![CDATA[PLEASE BACKUP YOUR iPhone BEFORE REMOVING iOS4!  I lost everything on my phone prior to removing iOS4 and didn&#8217;t think about saying this originally. In case you need help removing iOS4 from your iPhone 3G, here are the steps that &#8230; <a href="http://ericfickes.com/2010/07/how-i-removed-ios4-from-my-iphone-3g/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3><span style="color: #ffff00;">PLEASE BACKUP YOUR iPhone BEFORE REMOVING iOS4!  I lost everything on my phone prior to removing iOS4 and didn&#8217;t think about saying this originally</span>.</h3>
<p>In case you need help removing iOS4 from your iPhone 3G, here are the steps that I followed to downgrade my iPhone 3G to OS 3.1.3.  Before we get going, I&#8217;m not taking credit for these instructions since this is a cleaned up version of <a title="How to downgrade from iOS4 to 3.1.3" href="http://forums.macrumors.com/showthread.php?t=954719" target="_blank">this MacRumors forum post</a>.  Shout out to my buddy Tony Rodgers for sending me the original link.</p>
<h2>Required Downloads</h2>
<p>Before you get to the steps, be sure to download these two files first.</p>
<ul>
<li><a title="Download iPhone OS 3.1.3 restore file" href="http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7468.20100202.pbnrt/iPhone1,2_3.1.3_7E18_Restore.ipsw" target="_blank">iPhone1,2_3.1.3_7E18_Restore.ipsw</a> ( this is the OS 3.1.3 restore file )</li>
<li><a title="Go here and download the blackra1n tool that matches your OS ( mac or pc )" href="http://www.blackra1n.com/" target="_blank">blackra1n</a> ( pick the installer that matches your OS )</li>
</ul>
<h2>Restore iPhone 3G to OS 3.1.3</h2>
<ol>
<li>Connect your iPhone, open iTunes, then click your iPhone to go to the Summary screen.</li>
<li>While holding down Alt ( OSX ) or Shift ( windows ), click the Restore button.  If you held the correct key when clicking restore, you should get a File Open prompt.</li>
<li>Select iPhone1,2_3.1.3_7E18_Restore.ipsw that you downloaded earlier and let iTunes do it&#8217;s work.</li>
<li>After iTunes tries to verify the update, it should throw an error.  This error is normal, so disregard even though iTunes has left your iPhone 3G in restore mode.  Close iTunes.</li>
<li>With your iPhone still connected, open blackra1n and click &#8220;Make it rain&#8221;.</li>
<li>Manually power cycle your iPhone 3G if it doesn&#8217;t restart automatically for you.</li>
</ol>
<p>That&#8217;s all there is to it.  I know these steps work because it&#8217;s exactly what I did on my iPhone.  The last part of the uninstall is pretty hairy since I wasn&#8217;t able to close iTunes without unplugging my phone.  Also, when I ran blackra1n, my phone never rebooted on it&#8217;s own.  The screen went black and I just unplugged the iPhone and forced a restart.  When my iPhone booted up, I was back on 3.1.3.</p>
<p>I hope this helps somebody out because iOS4 on an iPhone 3G is horrible.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/07/how-i-removed-ios4-from-my-iphone-3g/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>

