Microsoft
Software
Hardware
Network
Question : TSQL: How to plug Nulls with Lookup values in same column and limited keys
I have a query that returns a data set which looks like this:
ID DATE GOAL CURRENT
1 2007-01-01 NULL 18
1 2007-02-01 NULL 18
1 2007-03-01 16 18
1 2007-04-01 NULL 18
1 2007-05-01 NULL 18
1 2007-06-01 17 18
In other words, the goal value is set quarterly, and resides only in the last period of the quarter. I need to plug this value into the prior two periods. The only thing I have to key off of is the ID (and maybe the year and month dateparts). I can't do anything about the source application responsible for the original insert.
Is there a way to do this with block-sql? Prefer avoiding the dreaded cursor, but at this point I'm desperate. It's less than 25k rows.
Answer : TSQL: How to plug Nulls with Lookup values in same column and limited keys
SELECT id, date,
SUM(goal) OVER (PARTITION BY DATEDIFF(MONTH, '20070101',date)/3) goal,
[current]
FROM tbl;
Random Solutions
Self-join a single table that includes 'parent-child' relation.
Cannot add event reminder in Outlook 2007 from linked Sharepoint 2003 calendar
How to write an Excel if statement that would accomplish figuring the percentage of a dollar amount based on the scale below:
What table contains company/database name - MS Dynamics GP
VB.NET Solution
Need batch to move files older than 8 days
Getting error message when trying to drop user from a database
Unknown error on Environ("Username")
Getting error message "The server tag is not well formed" on the line where I have a hyperlink control in my datagrid
Virtual Server Hardware recommendations needed