ANSI SQL Programming Test Results
sqlI took an online assessment last night about ANSI SQL Programming. It contained 39 questions which could each have up to three correct answers. You get points for selecting the correct answers and you get points taken away when if you don't select one of the correct answers or if you select an incorrect answer. Also, each answer is weighted differently based on how obvious it is.
I ended up with a score of 91 out of 100. I'm pretty happy with that. The questions that I had to skip were more related to terminology than actual code. Which I'm OK with, since I've never study theory or the like. But I'd like to learn more about the three normal forms. I know how to normalize a database, but I don't know which form is which. Hopefully a quick read will fix that.
Anyway, here are some nice charts that they sent me.


SQL Server List Length Function
microsoft, sql serverI know lists aren't good to store in a database, but something came up in which I needed to be able to get the list length of a VARCHAR filed. Instead of having to loop it each time, I decided to see what kind of functions were already out there. I found a count string function, but it wasn't exactly what I was looking for, so I took the idea and ran with it.
This function takes a list (VARCHAR) and delimiter (VARCHAR) and returns the number of items in the list.
/* UDF_LISTLEN ================================================== Created on 02/19/2008 by Robert Froehling - returns the length of a list - this was modified from count string function at the link below - http://www.sql-server-helper.com/functions/count-string.aspx */ CREATE FUNCTION UDF_LISTLEN( @list VARCHAR(8000), @delim VARCHAR(5)) RETURNS TINYINT BEGIN -- define the vars to use DECLARE @modString VARCHAR(8000) DECLARE @newString VARCHAR(8000) DECLARE @oldStringLen SMALLINT DECLARE @modStringLen SMALLINT DECLARE @newStringLen SMALLINT DECLARE @delimLen TINYINT DECLARE @diff TINYINT -- set some default vars SET @oldStringLen = LEN(@list) SET @delimLen = LEN(@delim) SET @modString = @list SET @modStringLen = LEN(@modString) -- if the first part of the string is the delim then remove it IF SUBSTRING(@modString, 1, @delimLen) = @delim BEGIN SET @modString = SUBSTRING(@modString, @delimLen + 1, @oldStringLen - @delimLen) SET @modStringLen = LEN(@modString) END -- if the last part of the string is the delim then remove it IF SUBSTRING(@modString, @modStringLen - @delimLen + 1, @delimLen) = @delim BEGIN SET @modString = SUBSTRING(@modString, 1, @modStringLen - @delimLen) SET @modStringLen = LEN(@modString) END -- count the lengths and setup the diff to return SET @newString = REPLACE(@list, @delim, '') SET @newStringLen = LEN(@newString) SET @diff = @modStringLen - @newStringLen + 1 RETURN @diff END
Here is a usage example.
DECLARE @list VARCHAR(500) DECLARE @delim VARCHAR(1) SET @list = 'fro,ev,jc,ds' SET @delim = ',' PRINT master.dbo.udf_listlen(@list, @delim)
Update: I should point out that I've only tested this on SQL Server 2000.
ColdFusion Thinks My List Is A Date
coldfusionI came across something interesting today when build a query for testing. I did the following:
<cfscript>
q = queryNew("id,name,list");
queryAddRow(q, 3);
querySetCell(q, "id", 1, 1);
querySetCell(q, "name", "robert", 1);
querySetCell(q, "list", "1,2,3", 1);
querySetCell(q, "id", 2, 2);
querySetCell(q, "name", "ryan", 2);
querySetCell(q, "list", "1,3", 2);
querySetCell(q, "id", 3, 3);
querySetCell(q, "name", "greg", 3);
querySetCell(q, "list", "3,4", 3);
</cfscript>Out of habit, I dumped the "q" to verify that I have what I want. When doing this, what do you think I got?
I thought I'd get an INTEGER (id) and 2 VARCHARs (name & list). Is that what you thought? Well, that's not the case. QuerySetCell determined that the "list" column values represent dates. This is what it gave me.

When I used 2 or 3 numbers in the list, that fell within some sort of date value range, ColdFusion set it's datatype to DATE. If I add rows that only have 1 list value, more than 3 list values, or list values that seem to break the DATE mold (e.g. "40,40"), then I'd get the VARCHAR list that I wanted.
So what is the lesson learned here? ALWAYS define your datatypes when using QueryNew.
Have you come across any other functions that produce unexpected results?
Reminder To Self - Cannot Concatenate NULL in SQL Server 2000
microsoft, sql serverIn SQL Server 2000, I'm not sure about 2005 yet, you can't concatenate on a NULL value. The result will continue to be NULL.
By running this you get an output of NULL.
DECLARE @my_string VARCHAR(20) SET @my_string = @my_string + 'something' PRINT @my_string
You have to set the variable to something other than NULL before using concatenation.
DECLARE @my_string VARCHAR(20) SET @my_string = '' SET @my_string = @my_string + 'something' PRINT @my_string
This had me hung up for almost an hour.
SQL Server Data Types (ntext, text, and image) To Be Removed
microsoft, sql serverI was doing some research on data types in various DB engines when you came across the SQL Server 2005 documentation on data types and found that the ntext, text, and image data types will be removed in a future version of SQL Server.
When you plan on upgrading to a new version of anything, make sure to check the documentation for any deprecated functionality that you're using.
This doesn't impact me at the moment, as we haven't even upgraded to 2005 yet.






Loading....