I was looking for a way to have all my tables have a unique GUID (Globally Unique ID) as well as a “Last Updated” column that would automatically update both on INSERT and on UPDATE.
Through a few hours of experimentation, I created the following:
CREATE TABLE dbo.testing (guid uniqueidentifier NOT NULL DEFAULT NEWID(), lastUpdated datetime2(7) NOT NULL DEFAULT GETDATE(), col1 nchar(10) NULL, col2 nchar(10) NULL) GO CREATE TRIGGER dbo.trLastUpdatedTesting ON dbo.testing AFTER UPDATE -- not insert! AS BEGIN
I am going through an exercise where I’m trying to find a way to compute stock metrics (technical indicators). What I need is a way to iterate over the rows in a database, computing each technical indicator, then putting that value into the table’s row for that date.
I found an example, and modified it to work on SQL SERVER 2008 R2. I hope you, too, find this solution extremely interesting:
DROP TABLE #google_stock GO create table #google_stock ( quote_date [datetime], open_price [decimal](6,2), close_price [decimal](6,2), high_price [decimal](6,2), low_price [decimal](6,2) ) GO

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 