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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help using OUTPUT parameter

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-06-29 : 07:38:43

Hi,

I'm writing a query, and I'm thinking its going to be alot better to use an OUTPUT parameter instead returning a whole dataset. I'm not sure if its possible with this specific query, or how to do it. Can anyone lend me a hand on this one?

I think this query is pretty self explanatory but I'll let it be known that I only need one value brougth back, and that is

"count(DISTINCT messageTo) as newRecipients"


Thanks very much!
mike123





CREATE PROCEDURE [dbo].[select_IM_NewMessageRecipients_count_OUTPUT]
(
@userID int,
@minutes int,
@newRecipients_OUTPUT [tinyint] OUTPUT
)
AS SET NOCOUNT ON

SELECT count(DISTINCT messageTo) as newRecipients FROM tblMessage WHERE messageFrom = @userID and date >= DATEADD (mi , @minutes, getDate())

AND messageTo NOT IN (SELECT messageFrom FROM tblMessage WHERE messageTo = @userID)


SELECT @newRecipients_OUTPUT = ???


GO


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-29 : 07:45:29
[code]CREATE PROCEDURE [dbo].[select_IM_NewMessageRecipients_count_OUTPUT]
(
@userID int,
@minutes int,
@newRecipients_OUTPUT [tinyint] OUTPUT
)
AS SET NOCOUNT ON
SELECT @newRecipients_OUTPUT = COUNT(DISTINCT messageTo)
FROM tblMessage
WHERE messageFrom = @userID
AND date >= DATEADD (mi , @minutes, GETDATE())
AND messageTo NOT IN (SELECT messageFrom FROM tblMessage WHERE messageTo = @userID)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-29 : 07:47:38
quote:
Originally posted by mike123


Hi,

I'm writing a query, and I'm thinking its going to be alot better to use an OUTPUT parameter instead returning a whole dataset. I'm not sure if its possible with this specific query, or how to do it. Can anyone lend me a hand on this one?

I think this query is pretty self explanatory but I'll let it be known that I only need one value brougth back, and that is

"count(DISTINCT messageTo) as newRecipients"


Thanks very much!
mike123





CREATE PROCEDURE [dbo].[select_IM_NewMessageRecipients_count_OUTPUT]
(
@userID int,
@minutes int,
@newRecipients_OUTPUT [tinyint] OUTPUT
)
AS SET NOCOUNT ON

SELECT @newRecipients_OUTPUT = count(DISTINCT messageTo) FROM tblMessage WHERE messageFrom = @userID and date >= DATEADD (mi , @minutes, getDate())
AND messageTo NOT IN (SELECT messageFrom FROM tblMessage WHERE messageTo = @userID)
GO






Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-29 : 07:48:14


Slow internet connection ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-29 : 08:11:06
Yes.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-29 : 08:58:57
quote:
Originally posted by khtan



Slow internet connection ?


KH
[spoiler]Time is always against us[/spoiler]




Seem someone's echo

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -