Skip to main content

Posts

Showing posts from 2006

Table Functions in SQL Server 2000 and up

I recently added a customer tagging feature to our billing system. Users needed to be able to see a list of associated tags in their reports, so I needed to be able to collect all tags for a customer into a single string. Below is a rough approximation of the table schema. I did some research, and ended up creating a user-defined function (UDF) that returns a TABLE variable. Inside the UFD, I used a table variable, a cursor (which I wanted to avoid) and ran a query with the COALESCE() function for each customer. I was able to use my UDF as if it were a temporary table in my reports. Otherwise, I would have had to duplicate this code for each report. Before accepting this solution, I tried various flavors of selecting, updating, etc. but I couldn't find a solution without using a cursor. The code below is an untested generic adaptation of my working solution. TABLE: Customers Customer_ID INTEGER, CustomerName VARCHAR(50) TABLE: Membership Member_ID INTEGER, ...

The Rails Way

There is an excellent article on recommended coding practices "The Rails Way" . The authors are espousing a commonly held coding practice - use base classes or mix-ins (Modules in Ruby) only when code would otherwise be repeated. This reinforces the DRY (Don't Repeat Yourself) philosophy that Ruby encourages and facilitates. A helpful reader offers further explanation for those Rails programmers who have not dug deeply into Ruby yet at Artistic Coding . Ruby is such an amazing and flexible language, but my "Day Job" is .Net, so I can not wait for Ruby.Net , Ruby CLR (or maybe here ), or whatever works. Ruby.Net and Ruby 2.0 (see YARV ). Microsoft is working on IQF (Integrated Query Framework), which will try to offer .Net users the same ease-of-use and elegance that ActiveRecords offers (ActiveRecords is a part of the Rails framework, but can be used separately). If Mono also implements IQF, I will be interested. We shall see.

Online Gaming with Eternal Lands

Note: I wrote this entry while I was still playing Eternal Lands. I have recently stopped playing, but I thought I should share my thoughts anyway. For the past few months, I have been spending time in a free online role playing game - Eternal Lands . The game allows "player kill", but only on certain maps or certain areas, and you receive a warning message before you enter these areas. I haven't joined a guild yet, and the game doesn't force you to do so. All-in-all, I like it, although it could use a lot more quests (I'm working on submitting a few ideas ). I have a few tips for new players. First, concentrate on fighting and building up will at least to 12 first, then start building physique. Do not add to ANY OTHER attributes EVER. Only add pairs of "pick points" to attributes, as odd values are wasted. Don't take any negative perks until you have reached level 25. I would advise against taking any positive perks as well. I took the art...

Installing Ubuntu Dapper Drake

A fellow IT guy walked past my desk and asked about the 400 MHz Celeron box that I had tied to my switch box. I informed him that this was my Linux test box. He said that we have much better boxes than that in our storage room, and invited me to shop. I pulled out a Dell 4100 - with an Intel 815 chipset and ATI Rage 128 Pro graphics. I plan on installing this one as a true server - Apache, Ruby, Rails, MySQL 5.0, and SSH. Here's how I did it: 1. Make an install ISO of Dapper Drake Flight 3 . 2. Select [Install As Server] at the install menu. 3. modify inittab for 3 consoles (put a # in front of other consoles). 4. edit /etc/apt/sources.list to add universe and multiverse 5. apt-get update & apt-get upgrade 6. a. apt-get install openssh-server mysql-client mysql-server ruby apache2 b. apt-get install libapache2-mod-scgi unzip rdoc 7. edit etc/ssh/sshd_config to dis-allow root access, change port number, and AllowLogin for my user id. 8. upgrade linux kernel to latest 686 v...

SQL Quirks - count and sum

I was reminded of a little quirk of SQL recently, and I thought I would share it with my readers. I will be going over the SQL in a manner suitable for beginners, but the quirk that I refer to could catch an intermediate student of SQL. I will use some simple SQL to illustrate my point. -- 1. create temporary table CREATE TABLE #test1 ( id int not null , name varchar(50) not null ) ; -- 2. declare variables DECLARE @cnt int, @sum int ; -- 3. compute statistics SELECT @cnt = count(*) FROM #test1 ; SELECT @sum = sum(id) FROM #test1 ; -- 4. print results to query analyzer PRINT '@cnt = ' + ISNULL( CONVERT(varchar, @cnt), '[NULL]') ; PRINT '@sum = ' + ISNULL( CONVERT(varchar, @sum), '[NULL]') ; -- 5. cleanup DROP TABLE #test1 ; If you will paste this sequence into query analyzer, and run it in a non-production database, you will see that it produces: @cnt = 0 @sum = [NULL] In step 1, we create an empty table. In step 2, we declare two variables, and their...