Tuesday, March 31, 2009

T-SQL INSERT From One Table Into Another

This is just a simple example of doing an INSERT INTO one table from another, with a hard-coded value thrown into the mix.

INSERT INTO ProductSubjects (ID, ProductID, SubjectID)
SELECT NEWID(), '52EB01B6-B768-4F9B-8F60-1A695A13D945', Subjects.ID
FROM Subjects

T-SQL SELECT Using CASE and String Concatenation

Here I'm selecting the ID field followed by a concatenation of 3 different subject fields, depending on whether or not the fields are NULL.

SELECT
ID,
CASE
WHEN Subject2 IS NULL THEN
Subject1
WHEN Subject2 IS NOT NULL AND Subject3 IS NULL THEN
Subject1 + ' : ' + Subject2
ELSE Subject1 + ' : ' + Subject2 + ' : ' + Subject3
END AS TheSubject
FROM Subjects
ORDER BY TheSubject

Saturday, March 28, 2009

Seeing Hourly Traffic with Google Analytics

Here's how to create a report in Google Analytics that will give you an hourly traffic report for your site.
  1. Go to Custom Reporting
  2. Click "Creat new custom report"
  3. Open the "Site Usage" section on the left and drag Pageviews (or anything else you're looking for) over to one of the blue metric sections on the right
  4. Open the "Visitors" section on the left and drag "Hour of the day" to the green dimension section on the right
  5. Click edit next to the preset title and give your report a title if you want
  6. Click Create Report