Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2009, 03:06 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default calculate two result set of sql statement

There is a situation where I need to calcuated two data within the stored procedure. And the sum of these two data should

return from stored procedure.Right now I am not concentrating on return value.

My problem is that I need the values return through the two select statement within @v1 and @v2, but when i execute this

procedure it returns me the select statement (string) within these variable. Please suggest me the appropriate way to do this.
I will appriciate any response. it will help me to go further into my solution.





ALTER PROCEDURE [dbo].[WeightageInASI]
@Quarter varchar(10),
@Sector varchar(100),
@CurrentYear varchar(10)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Weightagevalue float
DECLARE @v1 float, @v2 float, @v3 float

select @v1 = 'SELECT isnull(sum(Q.'+ @Quarter +'),0) as '+ @Quarter +' FROM CompanyClassification c INNER JOIN
QuarterlyCapitalisation Q ON C.BSC_CODE=Q.BSC_CODE WHERE
C.SECTOR = ' + Char(39) + +' ' + @Sector + Char(39) +' AND Q.'+ @Quarter +' !=0 AND YEAR= '+ Char(39) + @CurrentYear +

Char(39) +''
exec(@v1)

select @v2 = 'SELECT isnull(sum(Q.'+ @Quarter +'),0) as '+ @Quarter +' FROM CompanyClassification c INNER JOIN
QuarterlyCapitalisation Q ON C.BSC_CODE=Q.BSC_CODE WHERE
C.SECTOR = ' + Char(39) + 'Not In ASI' + Char(39) +' AND Q.'+ @Quarter +' !=0 AND YEAR= '+ Char(39) + @CurrentYear + Char(39)

+''
exec @v2
set @v3 = @v1 * 100 / @v2

end
 
Old December 15th, 2009, 05:11 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

use this code instead:

Code:
...
select @v1 = 'isnull(sum(Q.'+ @Quarter +'),0) as '+ @Quarter +' FROM CompanyClassification c INNER JOIN 
QuarterlyCapitalisation Q ON C.BSC_CODE=Q.BSC_CODE WHERE
C.SECTOR = ' + Char(39) + +' ' + @Sector + Char(39) +' AND Q.'+ @Quarter +' !=0 AND YEAR= '+ Char(39) + @CurrentYear + 

Char(39) +''
exec(@v1)
...





Similar Threads
Thread Thread Starter Forum Replies Last Post
result set rajesh_css SQL Language 2 May 18th, 2009 03:33 PM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
Show result during SQL statement rtr1900 ASP.NET 2.0 Basics 0 December 7th, 2006 06:51 AM
xml result set truncated in sql query analyzer xologist SQL Server 2000 2 March 22nd, 2004 05:23 PM
Result set jemacc SQL Server 2000 0 December 19th, 2003 07:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.