Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
arundhati
Starting Member
1 Post |
Posted - 2011-08-09 : 06:54:10
|
ALTER PROCEDURE [dbo].[SPTest] -- Add the parameters for the stored procedure here @host as nvarchar(100), @frmnth as int, @tomnth as int, @yr as intAS DECLARE @inbound as float DECLARE @outbound as float DECLARE @access_BW as nvarchar(50) DECLARE @db_cursor CURSOR DECLARE @c as int BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SET @db_cursor = CURSOR FAST_FORWARD FOR SELECT o.[Inbound],o.[Outbound],s.[Access bandwidth (Kbps)] FROM OP5Statistics1 o, Spider s WHERE o.[Host_name] = s.[Name in monitoring tool] and MONTH(Date1) BETWEEN @frmnth and @tomnth and DATEPART(weekday,Date1)<> 7 and DATEPART(weekday,Date1)<> 6 and o.[Host_name] = @host and s.[Name in monitoring tool] = @host OPEN @db_cursor FETCH NEXT FROM @db_cursor INTO @inbound,@outbound,@access_BW WHILE @@FETCH_STATUS = 0 BEGIN IF @inbound > .75 * Convert(float,@access_BW) or @outbound > .75 * Convert(float,@access_BW) BEGIN set @c = @c + 1 print @c END FETCH NEXT FROM @db_cursor INTO @inbound,@outbound,@access_BW END SELECT @c AS Count CLOSE @db_cursor DEALLOCATE @db_cursorENDwhen i am running this stored procedure its giving as output count = NULL were as it should return an integer value. please help me out by pointing to what are my mistakes.... its realy very urgent.... hope to get a reply soon....Arundhati Saha |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-08-09 : 07:18:35
|
quote: Originally posted by arundhati ALTER PROCEDURE [dbo].[SPTest] -- Add the parameters for the stored procedure here @host as nvarchar(100), @frmnth as int, @tomnth as int, @yr as intAS DECLARE @inbound as float DECLARE @outbound as float DECLARE @access_BW as nvarchar(50) DECLARE @db_cursor CURSOR DECLARE @c as int BEGIN-- initializeset @c = 0 -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SET @db_cursor = CURSOR FAST_FORWARD FOR SELECT o.[Inbound],o.[Outbound],s.[Access bandwidth (Kbps)] FROM OP5Statistics1 o, Spider s WHERE o.[Host_name] = s.[Name in monitoring tool] and MONTH(Date1) BETWEEN @frmnth and @tomnth and DATEPART(weekday,Date1)<> 7 and DATEPART(weekday,Date1)<> 6 and o.[Host_name] = @host and s.[Name in monitoring tool] = @host OPEN @db_cursor FETCH NEXT FROM @db_cursor INTO @inbound,@outbound,@access_BW WHILE @@FETCH_STATUS = 0 BEGIN IF @inbound > .75 * Convert(float,@access_BW) or @outbound > .75 * Convert(float,@access_BW) BEGIN set @c = @c + 1 print @c END FETCH NEXT FROM @db_cursor INTO @inbound,@outbound,@access_BW END SELECT @c AS Count CLOSE @db_cursor DEALLOCATE @db_cursorENDwhen i am running this stored procedure its giving as output count = NULL were as it should return an integer value. please help me out by pointing to what are my mistakes.... its realy very urgent.... hope to get a reply soon....Arundhati Saha
No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-08-09 : 07:25:59
|
or simple without cursor:SELECT count(*) as [Count]FROM OP5Statistics1 o, Spider s WHERE o.[Host_name] = s.[Name in monitoring tool] and MONTH(Date1) BETWEEN @frmnth and @tomnth and DATEPART(weekday,Date1)<> 7 and DATEPART(weekday,Date1)<> 6 and o.[Host_name] = @host and s.[Name in monitoring tool] = @hostand (o.Inbound > .75 * Convert(float,s.[Access bandwidth (Kbps)]) or o.Outbound > .75 * Convert(floats.[Access bandwidth (Kbps)])) No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|