Archive for May 4th, 2008
Tip of the Day : SQL Update from Joined Table
Updating a table with values from a Joined table.
I run into this question from the guys at work quite a bit, but it’s actually a pretty easy concept once you get the hang of it. If you have two tables that you want to sync values on, and you have a primary/foreign key you can join on, you’re all set.
Update Table1 Set Table1.ThisNeedsUpdated = Table2.WithThisNewValue From Table1 Inner Join Table2 on Table1.ID = Table2.ID
If you get stuck, just remember a few things.
- The table in your “Update” caluse should be the same table in your “From” clause.
- You can join additional tables, nested selects or common table expressions as well and update your main table with values from those as well.
- If you’re working with two tables that have similiar field names, it’s best to fully qualify those fields in your statement to make it more readable.
Please comment if you have any questions or can’t get this working. I’d be glad to help.
ASP.NET Custom Server Controls – Custom Collection
I’ve been battling with trying to find a best practice method for developing a custom control in ASP.NET that has nested child controls. Specifically, I want something that functions much like the Wizard Control. I started out with an control that exposed an ITemplate property and used the InstantiateIn method, but this was all done using User Controls and just felt wrong. I started digging around some more and found this link http://weblogs.asp.net/ngur/articles/144770.aspx. Aha! Now it’s starting to make a bit of sense.
The utlimate goal is to (again) have something akin to the Wizard Control. What I mean is this:

Nevermind the name of these children, just focus on the concept. If you implement this with ITemplate, it because rather difficult to do what I wanted to do. I kept running into the fact that ITemplate lets you place ANYTHING inside the “Child” tags and I didn’t want that. I eventually found a way to eliminate this, but again, it just felt wrong.
The link above provided a little more insight into how this is supposed to function. Combined with the invaluable knowledge I found on the web that the “WizardSteps” tag I’m trying to emulate is actually a WizardStepCollection property of the Wizard control, and suddenly I feel like I’m heading down the right path.
Anyone have any experience with this?