Wednesday, March 25, 2009

Lots Later

Well, at the end of the last posting I said "a little programming". Well, that turned into rather a lot of programming indeed! In T-SQL and VB.NET, mainly, along with a load of debugging other people's misconceptions about what they should be expecting.

Along the way of programming I discovered a number of useful things, like how to get a list of all the fields names in a database, how to search for code containing a string or strings inside SQL Server, and all sorts of other tid-bits!

Anyway, today I needed to take a table and set a field to a number all through the field. Easy enough, if it's just one number, but what if it's two or more numbers, and you have to distribute them so that record 1 gets number a, record 2 number b, etc. until you run out of numbers and then repeat the sequence over, until the end of the table? Oh yes, and you don't know in advance how many numbers there'll be to distribute!

declare @taPeople Table ( RowID int Primary Key Identity(1, 1),
PersonID int)
-- ----------------------------------------------------
-- Find out how many are needed
-- ----------------------------------------------------
select @intNrIDs = count(*)
from tblIDList
where CompanyID = @intCompany and
-- ----------------------------------------------------
-- Fill the table var. with the IDs we want to use,
-- and the Identity fied will number them for me
-- ----------------------------------------------------
insert into @taPeople
select PersonID
from tblPeople
where CompanyID = @intCompany
-- ----------------------------------------------------
-- Arrange for tblData also to have a contiguous
-- monotonic-increasing key (i.e. identity (1, 1))
-- ----------------------------------------------------
update dbo.tblData
set PersonID = (select PersonID
from @taPeople
where RowID = (DataRowID % @intNrIDs ) + 1) where CompanyID = @intCompany
-- ----------------------------------------------------

Well, I thought it kinda neat, 'cos it lets me do non-random distribution of data across all the records of a table - not a thing usually easily done without a cursor.


Yarn Stuff
Back to the subject that's been consuming this blog for the last few episodes - wool !

As always, we wnt to The GrindHouse Cafe in Haddonfield today (Tuesday) and I programmed and Tola and the other 25 or so ladies all knitted and chatted. One young lady in particular is Jessie, and she's just starting out knitting. So, here's a picture of Jessie and her very first piece of knitting ( a geek would call it a small enthalpy-enhanced area of the Universe, with great future prospects. I call it rather cool to watch someone fighting over what she terms "the first thing she's ever made". ). Anyhow, Jessie, Jenna, and Ali are great company and seriously intelligent (being med students!). The other two can knit well and are dragging Jessie into it too, which is a nice thing to do.

Next, we visited Loop and Nangelini on Philly's South Street last Friday. Loop because there was a book signing there, and Nangelini's because we were there and we like Nancy. In fact, the Loop visit turned into a double-header, because there was another book-signing next door, at Spool.

At Loop, The Better Half wanted a signed book. I might have lost her then, but the signature duly materialised. As you can imagine, the signature of a cartoon artist is seriously attractive.

Found Food

I have published quite a few recipes here on my blog over the last few years, and I hope that all my readers have tried at least some of the...