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 2000 Forums
 SQL Server Development (2000)
 can you not use a alias for a sum in sp's?

Author  Topic 

genic
Yak Posting Veteran

57 Posts

Posted - 2001-04-23 : 12:01:08
and as you see in the stored procedure below i am getting the sum of the hours and calling it 'totalTime' ..the store procedure works just great (tested it) ..but i always get the error of: Item cannot be found in the collection corresponding to the requested name or ordinal.
which basically means that it can not find that field name within the sql statement. when doing the sql statement outside of a store procedure..it works just fine. any ideas?

calling the stored procedure via a page like this


sSqlAllocatedHours = "sp_selectAllocatedHours'" & strDate1 & "', '" & strDate2 & "', '" & strOrg & "', '" & strDept & "', '" & strTeam & "'"
set rsAllocatedHours = objConn.Execute(sSqlAllocatedHours)
strAllocatedHours = rsAllocatedHours("totalTime")



Alter Procedure sp_selectAllocatedHours
@date1 datetime,
@date2 datetime,
@profileorg varchar(255),
@profiledept varchar(255),
@profileteam varchar(255)
As
declare @sql varchar(512)

if (@profileorg <> '')
BEGIN
set @sql = 'select sum(convert(decimal(10,4), b.hours)) as totalTime from profile as a inner join projecttime as b on (b.profileemail = a.profileemail)'

if (@date1 <> '') and (@date2 <> '')
BEGIN
set @sql = @sql+ 'where b.workdate between @date1 and @date2'
END

if (@profileorg <> '') and (@date1 = '') or (@date2 = '')
BEGIN
set @sql = @sql + ' where a.profile_org = @profileorg'
END

if (@profileorg <> '') and (@date1 <> '') or (@date2 <> '')
BEGIN
set @sql = @sql + ' and a.profile_org = @profileorg'
END

if (@profileorg <> '') and (@profiledept <> '')
BEGIN
set @sql = @sql + ' and a.profile_dept = @profiledept'
END

if (@profileorg <> '') and (@profiledept <> '') and (@profileteam <> '')
BEGIN
set @sql = @sql + ' and a.profile_team = @profileteam'
END
END
else
BEGIN
set @sql = 'select sum(convert(decimal(10,4), b.hours)) as totalTime from profile as a inner join projecttime as b on (b.profileemail = a.profileemail)'
END

select @sql
return


   

- Advertisement -