T-SQL Script to create a US States Table

Down and dirty. Pass it around.

GO
/****** Object: Table [dbo].[US_States] Script Date: 10/07/2008 15:32:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[US_States](
   [ID] [int] IDENTITY(1,1) NOT NULL,
   [Name] [nvarchar](50) NOT NULL,
   [Abbreviation] [nchar](2) NOT NULL
) ON [PRIMARY]

insert into US_States values ('Alabama' , 'AL')
insert into US_States values ('Alaska' , 'AK')
insert into US_States values ('Arizona' , 'AZ')
insert into US_States values ('Arkansas' , 'AR')
insert into US_States values ('California' , 'CA')
insert into US_States values ('Colorado' , 'CO')
insert into US_States values ('Connecticut' , 'CT')
insert into US_States values ( 'Delaware' , 'DE')
insert into US_States values ( 'District of Columbia' , 'DC')
insert into US_States values ( 'Florida' , 'FL')
insert into US_States values ( 'Georgia' , 'GA')
insert into US_States values ( 'Hawaii' , 'HI')
insert into US_States values ( 'Idaho' , 'ID')
insert into US_States values ( 'Illinois' , 'IL')
insert into US_States values ( 'Indiana' , 'IN')
insert into US_States values ( 'Iowa' , 'IA')
insert into US_States values ( 'Kansas' , 'KS')
insert into US_States values ( 'Kentucky' , 'KY')
insert into US_States values ( 'Louisiana' , 'LA')
insert into US_States values ( 'Maine' , 'ME')
insert into US_States values ( 'Maryland' , 'MD')
insert into US_States values ( 'Massachusetts' , 'MA')
insert into US_States values ( 'Michigan' , 'MI')
insert into US_States values ( 'Minnesota' , 'MN')
insert into US_States values ( 'Mississippi' , 'MS')
insert into US_States values ( 'Missouri' , 'MO')
insert into US_States values ( 'Montana' , 'MT')
insert into US_States values ( 'Nebraska' , 'NE')
insert into US_States values ( 'Nevada' , 'NV')
insert into US_States values ( 'New Hampshire' , 'NH')
insert into US_States values ( 'New Jersey' , 'NJ')
insert into US_States values ( 'New Mexico' , 'NM')
insert into US_States values ( 'New York' , 'NY')
insert into US_States values ( 'North Carolina' , 'NC')
insert into US_States values ( 'North Dakota' , 'ND')
insert into US_States values ( 'Ohio' , 'OH')
insert into US_States values ( 'Oklahoma' , 'OK')
insert into US_States values ( 'Oregon' , 'OR')
insert into US_States values ( 'Pennsylvania' , 'PA')
insert into US_States values ( 'Rhode Island' , 'RI')
insert into US_States values ( 'South Carolina' , 'SC')
insert into US_States values ( 'South Dakota' , 'SD')
insert into US_States values ( 'Tennessee' , 'TN')
insert into US_States values ( 'Texas' , 'TX')
insert into US_States values ( 'Utah' , 'UT')
insert into US_States values ( 'Vermont' , 'VT')
insert into US_States values ( 'Virginia' , 'VA')
insert into US_States values ( 'Washington' , 'WA')
insert into US_States values ( 'West Virginia' , 'WV')
insert into US_States values ( 'Wisconsin' , 'WI')
insert into US_States values ( 'Wyoming' , 'WY')
GO

Ben Folds Five Reunion

NYMEX Crude Oil Pod

Its been a while since I had a new post. Mainly because I've been working on an awesome Flex application for the Fleet Leasing Company where I work.

About 3 months ago I got a Yahoo Widget that reads the NYMEX for Light Sweet Crude and posts the price to my desktop ever 20 minutes or so. The owner of my company comes over a couple times a week and checks it out. Today he asked me to create one for our client website. So the cfc I made now drives the pod. Here is the code:

The CFC
<cfcomponent>
   <cffunction name="getOilPrice" access="public" returntype="string">
      <cfargument name="firstCatch" type="string" default="#HTMLEditFormat('<span class="tbl_num">')#">
<cfargument name="lastCatch" type="string" default="#HTMLEditFormat('</span>')#">
      <cfargument name="crudeURL" type="string" default="http://www.bloomberg.com/markets/commodities/energyprices.html">
<cfhttp url="#arguments.crudeURL#" resolveurl="Yes" throwOnError="Yes"/>
         <cfset nymex = #CFHTTP.FileContent#>
<cfset firstDmp = '#mid(nymex, 1, val(find(arguments.firstCatch, nymex, 0) + val(len(arguments.firstCatch)-1)))#'>
         <cfset leftNYMEX = ReplaceNoCase(nymex, firstDmp, '')>
<cfset secondDmp = '#mid(leftNYMEX, 1, val(find('.', leftNYMEX, 0) + 2))#'>
<cfset newNYMEX = secondDmp>
      <cfreturn newNYMEX>
   </cffunction>
</cfcomponent>
The Pod
<cfsetting enablecfoutputonly='true'>
<cfprocessingdirective pageencoding='utf-8'>
<!---
Name : NYMEX Crude Oil Price
Author : PodGenerator (based on archives.cfm by Raymond Camden)
--->


<cfmodule template='../../tags/podlayout.cfm' title='NYMEX Crude Oil Price'>
<!---
Your Pod text goes here -
Remember it has to be in cfoutput
tags or it will not be displayed
--->
<cfinvoke component="components.nymex" method="getOilPrice" returnvariable="newNYMEX">
   <cfinvokeargument name="firstCatch" value='<span class="tbl_num">'>
<cfinvokeargument name="lastCatch" value='</span>'>
<cfinvokeargument name="crudeURL" value="http://www.bloomberg.com/markets/commodities/energyprices.html">
</cfinvoke>
<cfoutput>
<div align="center">NYMEx Crude Oil Price as of:</div>
<div align="center">#dateFormat(now(), 'mmm/dd/yy')# #timeFormat(now(), 'HH:MM')#</div>
<div align="center">#dollarFormat(newNYMEX)#</div>
</cfoutput>      
</cfmodule>
<cfsetting enablecfoutputonly='false'/>

Feel free to use it, but don't be like Ray Horn and not pay homage to my greatness.

Created by Christopher Walker - www.SharedDynamics.com

SQL Injection attacks

First thing to say about this subject is this: If you aren't using stored procedures and scoping your variables with cfprocparam or cfqueryparam (if you use a plain ol' query) then you are moments away from a SQL injection attack and a potential total loss of data.

[More]

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner