<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Phillip&apos;s ColdFusion Blog - SQL</title>
			<link>http://www.phillipciske.com/blog/index.cfm</link>
			<description>createObject(&quot;component&quot;, &quot;YetAnotherCFBlog&quot;).init()</description>
			<language>en-us</language>
			<pubDate>Sun, 05 Sep 2010 00:56:54 -0700</pubDate>
			<lastBuildDate>Wed, 19 Aug 2009 05:07:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>pciske@gmail.com</managingEditor>
			<webMaster>pciske@gmail.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>pciske@gmail.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			<itunes:image href="" />
			<image>
				<url></url>
				<title>Phillip&apos;s ColdFusion Blog</title>
				<link>http://www.phillipciske.com/blog/index.cfm</link>
			</image>
			<itunes:explicit>no</itunes:explicit>
			
			<item>
				<title>The Persistant SQL UDF</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2009/8/19/The-Persistant-SQL-UDF</link>
				<description>
				
				I came across a very strange and unexpected problem with a SQL Server 2005 UDF yesterday that continues to puzzle me. First, the cast of players:

&lt;ul&gt;
&lt;li&gt;ColdFusion MX 7&lt;/li&gt;
&lt;li&gt;SQL Server 2005&lt;/li&gt;
&lt;li&gt;A table-valued function&lt;/li&gt;
&lt;li&gt;Puzzled developers&lt;/li&gt;
&lt;/ul&gt;

In case you are not familiar with table-valued functions, they are functions in SQL that return a table, as opposed to the more traditional scalar value.

We had to change the data type for one of the columns in the returned table from decimal to text to fix a bug. Nothing a simple ALTER FUNCTION statement could not handle. 

Script, run, test, same error, what?

Maybe something is cached on the SQL Server side. Let&apos;s try dropping and recreating the function.

Script, run, test, same error, ???

Something very odd was happening. Only after restarting the ColdFusion Application Server service did the error go away. 

I am still searching for an answer. Surely ColdFusion does not cache database object information...? 
				</description>
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Wed, 19 Aug 2009 05:07:00 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2009/8/19/The-Persistant-SQL-UDF</guid>
				
				
			</item>
			
			<item>
				<title>Version Control for Database Objects?</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2009/7/27/Version-Control-for-Database-Objects</link>
				<description>
				
				I have used a variety of version control methods and products over the years. In the beginning, I (infrequently) added a digit or date to the end of the file name, an effort that was largely ineffective and highly subject to user error. :-) Then, corresponding with a job change, I was introduced to version control software in the shape of CS-RCS from ComponentSoftware, based on GNU RCS. After a couple of years, the development team made the shift to Subversion, my personal favorite. To be complete, I will throw in a year of pain using Visual SourceSafe.  [More]
				</description>
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Mon, 27 Jul 2009 07:56:40 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2009/7/27/Version-Control-for-Database-Objects</guid>
				
				
			</item>
			
			<item>
				<title>Finding All Triggers in SQL Server</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2009/7/14/Finding-All-Triggers-in-SQL-Server</link>
				<description>
				
				Database triggers are sometimes difficult to track down. I needed to locate a list of all of the triggers in a database to check them for performance issues, and, when I turned to the INFORMATION_SCHEMA views, discovered there is not one for triggers. Oh well, back to interrogating the system tables.

Triggers are located in the sys.triggers table, so the following query delivered the information I needed:

&lt;code&gt;
SELECT
	o.name AS parent_object,
	t.name AS trigger_name,
	c.text AS trigger_def
FROM sys.sysobjects o 
	INNER JOIN sys.triggers t 
		ON t.parent_id = o.id
	INNER JOIN sys.syscomments c
		ON c.id = t.object_id
&lt;/code&gt; 
				</description>
				
				<category>SQL</category>				
				
				<pubDate>Tue, 14 Jul 2009 12:30:00 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2009/7/14/Finding-All-Triggers-in-SQL-Server</guid>
				
				
			</item>
			
			<item>
				<title>Finding a Random Row</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2008/9/30/Finding-a-Random-Row</link>
				<description>
				
				Every now and then I get a requirement to do something to a random table record. The most common is to retrieve a random record for display. Other times it is part of a data scrambling routine. So how is this done?

Most database platforms have a function that generates a unique identifier. SQL Server has NEWID(), which generates a GUID:

&lt;code&gt;
SELECT NEWID()

Example Output: 0B7869E5-1428-4CA9-9D5A-CDA0E9756DC2
&lt;/code&gt;

MySQL has RAND(), which generates a random floating-point value:

&lt;code&gt;
SELECT RAND();

Example Output: 0.93845168309142
&lt;/code&gt;

Using these functions, retrieving a random row from a table becomes as simple as:

&lt;strong&gt;SQL Server&lt;/strong&gt;
&lt;code&gt;
SELECT TOP 1 *
FROM mytable
ORDER BY NEWID()
&lt;/code&gt;

&lt;strong&gt;MySQL&lt;/strong&gt;
&lt;code&gt;
SELECT *
FROM mytable
ORDER BY RAND()
LIMIT 1;
&lt;/code&gt;

So what is really going on behind the scenes? The key to the randomness is the ORDER BY clause. As each row in the table is evaluated, it is assigned a unique value via the NEWID() or RAND() function. The value changes for each row and each time the query is executed. 
				</description>
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Tue, 30 Sep 2008 13:20:00 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2008/9/30/Finding-a-Random-Row</guid>
				
				
			</item>
			
			<item>
				<title>Coding Standards</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2008/6/26/Coding-Standards</link>
				<description>
				
				I admit, I am a &lt;a href=&quot;http://www.coldfusionjedi.com/index.cfm/2008/4/22/What-makes-a-code-diva&quot;&gt;code diva&lt;/a&gt;. I want to see and write clean, clear, prettified code. I firmly believe that all programmers (and teams) should have, and more importantly follow, a set of coding standards. A few of my personal CF quirks are:

&lt;ul&gt;
&lt;li&gt;Tabs not spaces for code indentation.&lt;/li&gt;
&lt;li&gt;Functions are camel-cased, e.g., querySetCell and arrayToList.&lt;/li&gt;
&lt;li&gt;Variables are camel-cased and descriptive, e.g., currentRecord and dateOfBirth.&lt;/li&gt;
&lt;li&gt;Component names are capitalized, e.g., User and UserService.&lt;/li&gt;
&lt;li&gt;SQL keywords are upper case, e.g., SELECT username FROM users.&lt;/li&gt;
&lt;li&gt;Use implicit boolean function results, e.g., &amp;lt;cfif structKeyExists(...)&amp;gt;.&lt;/li&gt;
&lt;li&gt;Use structKeyExists over isDefined whenever possible.&lt;/li&gt;
&lt;li&gt;And so on.&lt;/li&gt;
&lt;/ul&gt;

The important concept behind coding standards is not necessarily the nitty-gritty details of what is good and what is bad, but the discipline it provides your coding efforts. Consistency in coding is more important than the (endless) debates about which code formatting template is more readable or which function is better. If you cannot read your own code because you never structure it the same way twice then you have only yourself to blame. 
				</description>
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Thu, 26 Jun 2008 09:36:00 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2008/6/26/Coding-Standards</guid>
				
				
			</item>
			
			<item>
				<title>Building a Date Table with ColdFusion</title>
				<link>http://www.phillipciske.com/blog/index.cfm/2008/4/24/Building-a-Date-Table-with-ColdFusion</link>
				<description>
				
				If you have ever worked with a data warehouse, or a complex, date-sensitive application, then you have probably come across a date dimension table. Simply put, a date dimension table is a lookup table that contains one record per date. Each record has information about that date, such as the day of the week, the quarter it falls in, and so on. Many DBAs come armed with a SQL script that creates and populates a date dimension table. If you are not a SQL adept, why not use the power of ColdFusion?

Each record in a date dimension table describes a date, so our table will have the following columns:
&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;date&lt;/strong&gt; - the full date&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;year&lt;/strong&gt; - the date&apos;s year&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;month&lt;/strong&gt; - the date&apos;s month number&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;month_desc&lt;/strong&gt; - the month&apos;s name&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;day&lt;/strong&gt; - the date&apos;s day&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;quarter&lt;/strong&gt; - the date&apos;s quarter within the year&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;day_of_week&lt;/strong&gt; - the date&apos;s day of week number&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;day_of_week_desc&lt;/strong&gt; - the day of week&apos;s name&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;day_of_year&lt;/strong&gt; - the date&apos;s day number within the year&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;week_of_year&lt;/strong&gt; - the date&apos;s week number within the year&lt;/li&gt;
&lt;/ul&gt;

In SQL Server:

&lt;code&gt;
CREATE TABLE days (
	[days_id] int NOT NULL IDENTITY(1,1) PRIMARY KEY,
	[date] smalldatetime NOT NULL,
	[year] tinyint NOT NULL,
	[month] tinyint NOT NULL,
	[month_desc] varchar(10) NOT NULL,
	[day] tinyint NOT NULL,
	[quarter] tinyint NOT NULL,
	[day_of_week] tinyint NOT NULL,
	[day_of_week_desc] varchar(10) NOT NULL,
	[day_of_year] tinyint NOT NULL,
	[week_of_year] tinyint NOT NULL
)
&lt;/code&gt;

Now that the table is created, it needs data. Populating the data is simply a big loop using the many different CF functions for splitting and formatting dates. In this case, I will generate a script that can then be run in a database query tool, such as Query Analyzer:

&lt;code&gt;
&lt;cfset currentDate = createDate(2000, 01, 01)&gt;
&lt;cfset targetDate = createDate(2008, 12, 31)&gt;

&lt;cfloop condition=&quot;dateDiff(&apos;d&apos;, targetDate, currentDate) LTE 0&quot;&gt;
	&lt;cfoutput&gt;
		INSERT INTO days (date, year, month, month_desc, day, quarter, day_of_week, day_of_week_desc, day_of_year, week_of_year)
		VALUES (
			&apos;#createODBCDate(currentDate)#&apos;,
			#year(currentDate)#,
			#month(currentDate)#,
			&apos;#monthAsString(month(currentDate))#&apos;,
			#day(currentDate)#,
			#quarter(currentDate)#,
			#dayOfWeek(currentDate)#,
			&apos;#dayOfWeekAsString(dayOfWeek(currentDate))#&apos;,
			#dayOfYear(currentDate)#,
			#week(currentDate)#
		)
	&lt;/cfoutput&gt;
	&lt;cfset currentDate = dateAdd(&quot;d&quot;, 1, currentDate)&gt;
&lt;/cfloop&gt;
&lt;/code&gt;

In the above example, the date dimension table will contain one record for each day between January 1, 2000 and December 31, 2008. In the real world you will probably use a longer timespan, depending on your needs. 
				</description>
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Thu, 24 Apr 2008 13:56:00 -0700</pubDate>
				<guid>http://www.phillipciske.com/blog/index.cfm/2008/4/24/Building-a-Date-Table-with-ColdFusion</guid>
				
				
			</item>
			</channel></rss>