Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better way
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Application:
Desktop
Miscellaneous
Thread ID:
01423336
Message ID:
01423339
Views:
64
This message has been marked as a message which has helped to the initial question of the thread.
You can do it in one query
Select 
		@TotalProcsAssigned = count(*), 
		@TotalCardsAssigned = sum(case when cardassigned > 0 then 1 else 0 end)
	from dbo.meetproc where meetingnumber=@tiMeetID	 
>I'm wondering if there is a better way to write this function? I'm populating two variables which I then use in the returnvalue. Basically there could 1 or many records for each meetingnumber in the meetproc table. There is a int field in the meetproc table that stores a card number if assigned or a 0 if no card has been assigned. This function is getting called from the main stored procedure, so for each record returned in the main query, this function is calling two more queries. It works correctly and returns valid data, I'm just in the process of trying to optimize for a big load. Thanks in advance.
>
>
>ALTER FUNCTION [dbo].[Get_CardsAssignedNumeric]  (@tiMeetID int)  
>RETURNS varchar(10) AS  
>BEGIN 
>     Declare @returnValue varchar(10)
>     set @returnValue=' '
>     declare @TotalProcsAssigned int
>     declare @TotalCardsAssigned int 
>     set @TotalProcsAssigned = (Select count(*) from dbo.meetproc where meetingnumber=@tiMeetID)
>     set @TotalCardsAssigned = (Select count(*) from dbo.meetproc where meetingnumber=@tiMeetID and cardassigned > 0)
>     set @ReturnValue=cast(@TotalCardsAssigned as varchar(2))+' of '+cast(@TotalProcsAssigned as varchar(2))
>
>     return (@returnValue)
>END
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform