Tuesday, September 30, 2008

Alter Column

ALTER TABLE Minutes
ALTER COLUMN Rate decimal(6,4)
GO

Thursday, September 25, 2008

Update with JOIN

UPDATE cmp SET cmp.[Name] = mp.[Name]
FROM ClientPlans cmp
INNER JOIN Plans mp ON cmp.PlanID = mp.PlanID


-- A bit more complex example

UPDATE cs SET cs.[BankID] = c.[BankID], cs.[StartDate] = c.[StartDate]
FROM ClientSales cs
INNER JOIN Clients c ON (c.LocationID = cs.LocationID
AND c.LastName = cs.LastName
AND c.PhoneNumber = cs.PhoneNumber
AND c.Code = cs.Code
AND c.StartDate = DATEADD(hour, -2, cs.StartDate)
)