Associate
- Joined
- 6 Oct 2008
- Posts
- 41
Hi folks,
Hope someone can help me with this.
I need to get monthly figures out of our database and create a report.
I have created a stored procedure to get this information, but when debugging in visual studio I find that one of the variables isn't being popuated.
Here is the procedure:
The variable in question is @extract_dates within the cursor.
Hope someone can help me with this.
I need to get monthly figures out of our database and create a report.
I have created a stored procedure to get this information, but when debugging in visual studio I find that one of the variables isn't being popuated.
Here is the procedure:
Code:
BEGIN
DECLARE @extract_dates nvarchar(64), @month nvarchar(64), @extract_date nvarchar(64)
-- Insert statements for procedure here
DECLARE app_cursor CURSOR FOR
SELECT DISTINCT TOP (100) PERCENT { fn MONTHNAME(EntryDate) } AS Month, MAX(EntryDate) AS ExtractDate
FROM dbo.Applications
WHERE (sqlAcYear = '2010')
GROUP BY { fn MONTHNAME(EntryDate) }
ORDER BY ExtractDate
OPEN app_cursor
FETCH NEXT FROM app_cursor INTO @month, @extract_date
WHILE @@FETCH_STATUS = 0
BEGIN
SET @extract_dates = ', CONVERT(DATETIME, ''' + @extract_date + ''', 102)' + @extract_dates
FETCH NEXT FROM app_cursor INTO @month, @extract_date
END
CLOSE app_cursor
DEALLOCATE app_cursor
END
SET @extract_dates = SUBSTRING(@extract_dates, 1, LEN(@extract_dates)-1)
BEGIN
SELECT DISTINCT TOP (100) PERCENT { fn MONTHNAME(EntryDate) } AS Month, EntryDate,
SUM(DISTINCT sqlp + sqlack + sqlao + sqlrw + sqlrd + sqlapa + sqliq + sqldna + sqlintv + sqlna + sqlowl + sqlwdrw + sqliap + sqlconfa + sqlconfb) AS Applications
FROM dbo.Applications
WHERE (sqlAcYear = '2010')
GROUP BY EntryDate, { fn MONTHNAME(EntryDate) }
HAVING EntryDate IN (@extract_dates)
ORDER BY EntryDate
END
The variable in question is @extract_dates within the cursor.