Can Not Edit Hierarchyid in MS SQL SMS Editor

I’m basing my current project around SQL 2008’s hierarchyid data type, which is completely new to me. One frustrating issue I have found is the inability to edit any hierarchyid type’s data as a string inside the Microsoft SQL Server Management Studio’s edit feature. Granted I can control the data via the New Query feature, but I tend to use the interactive editor for quick and easy access to my data during the development process.

Take the following example:

Notice the hierarchyid data is converted into a string to be shown. However if you where to try and update the current value of ‘/1/’ to ‘/1/1/’ or update the current NULL value to ‘/1/1/’ then you would receive an error stating “Invalid cast from ‘System.String’ to ‘Microsoft.SqlServer.Types.SqlHierarchyId'”.

I’m not sure what data would even be acceptable in the field. I tried entering ‘0x5AC0’ for the NULL data and still received an error.

So from what I can see is this data type is unchangeable inside the editor.

The workaround for this would be to run the following TSQL:

UPDATE Table1
SET Question_Hierarchy_ID = '/1/1/'
WHERE ID=1

Word Wrap in ColdFusion Builder

I don’t know how many times I’ve had to lookup how to turn on word wrap in ColdFusion Builder. I’m guessing most people will only need to do this once, but I’m constantly messing around with new installations and alpha/beta releases. So mostly as a reference for myself, here’s how to turn on word wrap inside ColdFusion Builder:

  1. Open Window > Preferences from the toolbar
  2. Go to HTML > Editors in the left navigation
  3. Click the Advanced tab
  4. Click the checkbox for “Enable word wrap (requires editor restart)”
  5. Click the “OK” button
  6. Restart ColdFusion Builder

Saving Your Life Wirelessly

As some of you may know I am a volunteer EMT with a small town in Nebraska. About a year ago we, along with many other departments, purchased an upgraded Defibrillator unit.

Many picture a Defibrillator being those two paddles that jolt you back to life. While those still exist in many different forms, the more common unit is much more simple, yet much more complex. They’ve replaced the paddles with a set of pads that stick to your skin. Just slap them on and free your hands for other use.

Another misconception is that the jolt the Defibrillator magically starts your heart. It actually does the opposite. When you have what’s called a “shock-able heart rhythm” your heart is actually beating too shallow, too fast, randomly, or out of sequence. The shock delivered actually stops your heart so it can reset itself. It’s kind of like when the power goes out on a server and then automatically turns back on when the power comes back on.

It used to be that shocking you would literally cook part of your heart and surrounding tissue because it was such an overpowered and inefficient power surge. They’ve since then fixed that automatically tuning the power output and frequency to be the most efficient and least damaging as possible.

But outside of adding a computer to regulate the shock and changing out the paddles the concept has pretty much stayed the same. It’s a proven way to save a person’s life with specific and deadly cardiac issues.

What has changed is what’s considered the STEMI (ST segment elevation myocardial infarction) Alert. When you have a blocked artery providing the necessary blood flow to the heart every second counts. Each second that passes means more heart muscle that dies. In this case the national goal is to get you into surgery within 90-minutes of onset.

Lets say you are having chest pain and an ambulance arrives. There is the possibility that you may get the attention of either an EMT such as myself or a Paramedic. EMT’s will use the automated features of the Defibrillator. If you are going into cardiac arrest we place the two pads on you and let the computer take over advising us when to shock or to perform CPR. We can also place additional leads to get an all-around picture of your heart. However we are not trained to read or interpret the wave segments that those leads produce.

Technology now steps in. Either via a wireless modem or a Bluetooth connection to a cell phone we can transmit your EKG readout to the hospital we are headed to. There they can interpret your readout and prepare further if needed. The hospital can now advise a cardiologist or get the Cath Lab ready to receive you.

Now if you have a Paramedic respond to your situation they are trained to interpret your EKG readout and take additional actions. Not only can they inject potentially life saving drugs but they can activate the STEMI alert. At this point they alert the hospital of the elevated ST segment on your EKG and then also send the EKG readout wirelessly to the hospital for a team to confirm the STEMI.  This essentially bypasses the emergency department upon arrival and sends you directly to the Cath Lab.

In a recent case a man had a life-saving balloon in his artery within 26 minutes of onset. That’s 1/3 the time of the 90 minutes national goal. This is thanks to the remote view the hosptial had of the patients heart while en-route to the hospital. Some departments have gone a little further and provide a direct audio/visual link between the patient/responder and the hospital staff.

We will continue to see remote technological innovation in the health care industry from an emergency response to in-home care. Doctors already have the ability to use their smartphone to bring up a hospital patient’s live EKG and vitals from anywhere in the world reducing response time to a potentially life-threatening or life-diminishing situation.

hierarchyid Data Type Not Supported in ColdFusion 9

Microsoft SQL 2008 introduced the hierarchyid datatype helping with child/parent relationships. However this causes an issue if you try to select its data via ColdFusion’s Microsoft SQL Server driver. This breaks in ColdFusion 9.0.1 and I assume prior versions.

Example Table:

CREATE TABLE Org_T1
(
EmployeeId hierarchyid PRIMARY KEY,
EmployeeName nvarchar(50)
)

Example SQL Call:

SELECT * FROM Org_T1

Now first of all you should try to avoid “SELECT *” when possible anyway to increase efficiency. Otherwise the table columns are looked up before querying for results, adding an extra process step.

The way around this would be to list the columns you actually need in the select statement. If you need the data from the “EmployeeId” column you could append the “.ToString()” function to the column name. Example:

SELECT EmployeeId.ToString(), EmployeeName
FROM Org_T1

This will in effect change what data you receive however. The raw data looks something like “0xf0”. The result of the ToString() method looks something like “\1\” and I believe will be of varchar type.

There is a bug entry with Adobe here: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=83590 . Feel free to go vote on this issue to increase its visibility with the ColdFusion team.

NuVal – My New Grocery Shopping Buddy

In Omaha there a quite a few supermarkets to choose from for groceries including Bag and Save, Bakers, Hy-Vee, No Frills, Super Saver, Walmart and more. But I’ve taken notice of one lately: Hy-Vee. They have started to make a move similar to Walgreens and Walmart; they have begun rebuilding or remodeling their stores from cookie-cutter box stores to a more inviting and unique stores.

This transition includes promoting more healthy and organic foods, kind of a middle-man between store XYZ and Whole Foods (which I’ve never been to). But was has been bringing me back more and more is their prominent displays of the NuVal scores. They are an easily recognizable icon next to each product’s price bar that contains a number from 1-100. The greater the number, the healthier the food choice for that food category.

What has caught my attention are facts such as Kraft Fat Free Italian Dressing is has a worse rating than the original. Another example would be noticing the salted and non-salted canned green beans. I’m going to put the same amount of salt on my green beans after I cook it, so I might as well start with none, thus increasing the product’s NuVal score by quite a few points. Even going after the frozen broccoli, some have a higher score because they are preserved or seasoned differently.

Continue reading

SQL – Delete Orphans

In the 1930’s Miss Hannigan wanted to delete orphan Annie, but now we have child neglect laws that prohibit that. Good thing we now have SQL.

Lets say we have two SQL tables that contains names of team members. One is for softball and one is for baseball. We want to remove all players from softball that do not play baseball. You could do this in a loop or a subquery, but if you have team data from the past 100 years this may become quite costly.

Here’s a quick way to make this happen:

DELETE S
FROM Softball S
LEFT JOIN Baseball B ON (S.Name = B.Name)
WHERE S.Name IS NULL

What this is doing is matching the table Softball with Baseball. Any orphaned Softball players (no match with Baseball) end up getting deleted.

Understanding Hexadecimal Color Values

I’ve known about hexadecimal color values for HTML probably since 1994, back in Netscape Navigator Beta days. I’ve always known that they represent a group of Red-Blue-Green values, that when modified you get a new color, however slight or dramatic. Each position can have a value of 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e or f.

But I never really understood why such a silly system that required me to open Photoshop or use Dreamweaver to find the color I’m looking for; that is until today.

Most of us humans do math with a base of 10 (1, 10, 100…). However computer binary code uses a base of 8 (8, 16, 32, 64, 128… look familiar from your SD memory cards?) Hexadecimal has a base of 16, which is easy for a computer to use since 8 + 8 = 16.

Also remember that most visible colors can be reproduced using a mixture of red, green or blue (primary colors) thus we have the RGB groupings.

So “000000” is black and “FFFFFF” is white. In otherwords “000000” has no color and “FFFFFF” has all the color. So what if you want just a little red? Something like “010000” should do it. But what if you want a lot of red? Try “FF0000”. Yellow? “Try “FFFF00”. But this is the basics most of us know.

But where does the alphabet come into play? Can’t seem to get that one position above 9 can you? So use the alphabet to keep adding on top of that 9. So the value of F basically equals a 15 fit into one placeholder. If you want to go to 16 you’d start back at 0 and add a 1 to the previous place holder thus “0F0000” becomes “100000” for that little bit of red.

If this explanation is boring you or just confusing – watch a great short video about this at Nettuts+ .

After I watched this video I now have a clear understanding of what is going on here instead of just winging it via an IDE.

Global AJAX Loading Spinners

Many sites include what are known as AJAX Spinners. They are little graphics that show up on a web page that show something is happening behind the scenes. This is most commonly used when an AJAX request is being made and the end-user is waiting for a response.

There are many different ways you can make this happen.

One is to show and hide the spinner inside each AJAX method. Another is to show and hide the spinner inside the jQuery $.ajaxSetup configuration.

If you load individual spinners for each call this is a pain and can be cluttering. If you load a common spinner you can end up hiding it before a parallel request is finished unless you look at a queue, which is also a pain.

One easy way around all this confusion is to use jQuery’s global AJAX handlers: .ajaxStart and .ajaxStop (also look at .ajaxError)

First setup a common spinner container and graphic.

<style>
#ajaxSpinnerContainer {height:11px;}
#ajaxSpinnerImage {display:none;}
</style>

<div id="ajaxSpinnerContainer">
<img src="/images/ajax-loader.gif" id="ajaxSpinnerImage" title="working...">
</div>

One great place to generate these spinners is ajaxload.info.

The next step is to show the spinner when any AJAX request has begun and hide it when all AJAX requests have completed.

$(document)
.ajaxStart(function(){
    $("#ajaxSpinnerImage").show();
})
.ajaxStop(function(){
    $("#ajaxSpinnerImage").hide();
});

This quick and easy method avoids all the other headache associated with all the other techniques out there as long as you want the spinner shown in a single container.

#ajax, #jquery, #spinner

jQuery Templates

I decided to dig into the new official jQuery Template Plugin developed from Microsoft yesterday. After I finally got the darn thing to work it makes inserting formatted HTML populated with data way easier.

After doing some searches on Google I kept finding articles that announce that Templates would be built into the version 1.5 core. I continued down the path coding by example and researching the API Docs. However I kept running into “tmpl is not a function”. After some continued research I finally found a tiny little comment made by John Resig that it in fact did not make it into the 1.5 release. So now that error makes sense.

To resolve this issue you must still load the jQuery plugin. It appears the plugin is still in beta stages and is available for download from Github or the Microsoft CDN.

Before I’ve been unable to use Microsoft’s CDN because it did not have SSL. But I went ahead and tested to see if they now have it included, and they do!

Here’s how I use it:

<script src="//ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

This will automatically call it via http or https depending upon the current browser protocol being used.

See a related blog for jQuery on Google’s CDN here.

#cdn, #google, #jquery, #microsoft, #plugin, #template

Detect Mobile Browsers

I’m still fairly new to the mobile platform programming and I’ve never been able to find a good way to detect if you’re coming via a mobile browser or a full browser – until now. Usually what I do is put this in my normal page headers and redirect them to a mobile directory if mobile is detected.

Thanks to Ray Camden‘s suggestion, check out Detect Mobile Browser.

This site has contains open source mobile phone detection scripts for 15 languages / apps.

List includes: Apache, ASP, ASP.NET, ColdFusion, C#, IIS, JSP, JavaScript, jQuery, nginx, node.js, PHP, Perl, Python, and Rails

The ColdFusion script is pretty straight forward and uses a regular expression to figure it all out.

Continue reading

#mobile