<?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>rabidGadfly &#187; cf_sql_date</title>
	<atom:link href="http://rabidgadfly.com/tag/cf_sql_date/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Use cf_sql_timestamp for MS SQL and MySQL date types</title>
		<link>http://rabidgadfly.com/2009/03/use-cf_sql_timestamp-for-mssql/</link>
		<comments>http://rabidgadfly.com/2009/03/use-cf_sql_timestamp-for-mssql/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 19:11:42 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[cfqueryparam]]></category>
		<category><![CDATA[cf_sql_date]]></category>
		<category><![CDATA[cf_sql_timestamp]]></category>
		<category><![CDATA[ms sql]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=101</guid>
		<description><![CDATA[Hopefully, if you&#8217;re using ColdFusion, you&#8217;re already using cfqueryparam in your queries for better performance and security against SQL Injection attacks. If you&#8217;re not, you should read this. When using cfqueryparam you specify a value and an SQL type. Dates can be assigned two different types, cf_sql_date and cf_sql_timestamp. cf_sql_date is intended to be used [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully, if you&#8217;re using ColdFusion, you&#8217;re already using <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_18.html">cfqueryparam</a> in your queries for better performance and security against SQL Injection attacks. If you&#8217;re not, you should read <a href="http://www.forta.com/blog/index.cfm/2005/12/21/SQL-Injection-Attacks-Easy-To-Prevent-But-Apparently-Still-Ignored">this</a>.</p>
<p>When using cfqueryparam you specify a value and an SQL type. Dates can be assigned two different types, cf_sql_date and cf_sql_timestamp. cf_sql_date is intended to be used for date types in DB2 and Informix. If you&#8217;re using MS SQL Server, you should use cf_sql_timestamp.</p>
<p>cf_sql_timestamp maps  to the datetime and smalldatetime data types in MS SQL Server. Although cf_sql_date works in many instances, it does not work in all instances. I ran into this issue when evaluating whether a date equaled a certain date value. For example:</p>
<pre><code>
SELECT *
FROM myTable
WHERE create_dt = <cfqueryparam type="cf_sql_date" value="2099-12-31  23:59:59" />
</code></pre>
<p>When I ran the query in SQL Query Analyzer (minus the cfqueryparam of course), I received the expected results. When I ran it inside a ColdFusion page I received an empty result set. Once I changed to timestamp, I received my results.</p>
<pre><code>
SELECT *
FROM myTable
WHERE create_dt = <cfqueryparam type="cf_sql_timestamp" value="2099-12-31  23:59:59" />
</code></pre>
<p>I haven&#8217;t tested the code with mySQL, and mySQL isn&#8217;t listed in the livedocs cross-reference table so I don&#8217;t know what kind of effect can be seen there, though I&#8217;d be interested to find out.</p>
<p><strong>UPDATE:</strong> I got two great tips from comments. According to sebastiaan cf_sql_timestamp should be used with MySQL as well as MS SQL Server. And Ben Nadel adds that cf_sql_longvarchar should be used for text fields. Great info. Thank you both!</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2009/03/use-cf_sql_timestamp-for-mssql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

