Jbenson,
I will repost it since I thought it was there but noone else seems to see it:
the part that does not seem to work is: select @Qual3Count = count(distinct isnull(@Type,'') ) from @MasterTable where AAIA_ID = @AAIA
for this the base records would be:
1 W/ oop
1 W/o oop
1 W/o oop
I am expecting to see a 2 and I keep getting a 1
My procedure is:
declare @MasterTable table(AAIA_ID int
,Model_Name varchar(30)
,Nameplate varchar(30)
,Type varchar(10)
,Liters varchar(4)
,Quarts numeric(18,2)
,Filt varchar(1)
,Note varchar(3)
,Notes varchar(600)
)
insert into @MasterTable
select AAIA_ID
,Model_Name
,Nameplate
,Type
,Case When Liters = 'NA' Then '0' Else Liters End As Liters
, case When Liters = 'NA' Then 0 Else convert(numeric (18,2), Liters) * 1.0567 End as Quarts
,Filt
,a.note
,b.Descript
from
AccessSpecs.dbo.X_OILCAP a left outer join
NewNote b on a.note = b.note
where liters is not null and aaia_id = 1315263
order by AAIA_ID
select * from @MasterTable
-------------------------------------------------------------------------------------------
Declare @AAIA int
,@Model_Name varchar(30)
,@Nameplate varchar(30)
,@Type varchar(10)
,@Liters varchar(4)
,@Quarts numeric(18,2)
,@Filt varchar(1)
,@Note nvarchar(3)
,@Notes varchar(600)
,@HTMLStart varchar(8000)
,@HTMLEnd varchar(8000)
,@HTMLBody varchar(8000)
,@Qual1Count int
,@Qual2Count int
,@Qual3Count int
Declare @TableName varchar(150)
Set @TableName = 'Engine Oil Capacity'
Declare @copyright varchar(255)
set @copyright = '<TD align=Center Size-6 Colspan =3 nowrap\><FONT>Copyright © 2005 by Motor Information Systems, a division of Hearst Publishing, Inc. All rights reserved.</font></TD>'
Declare @caption varchar(255)
Select @Caption = dbo.caption(@TableName)
Declare @header varchar(200)
set @header = '<html><head><title>' + @TableName + '</title></head><body>'
--print @caption
set @HTMLStart = @header + '<table>'+ @caption
set @HTMLEnd = '<tr>'+ @copyright + '</tr>' + '</table></body></html>'
--First Curson Get AAIA Id numbers and loop through table
declare AAIA cursor for select distinct AAIA_Id from @mastertable
open aaia
fetch next from AAIA into
@AAIA
while @@fetch_status = 0
begin
--Second Cursor
declare Processing1 cursor for Select * from @MasterTable where AAIA_ID = @AAIA
open Processing1
fetch next from Processing1 into
@AAIA
,@Model_Name
,@Nameplate
,@Type
,@Liters
,@Quarts
,@Filt
,@Note
,@Notes
select @Qual3Count = count(distinct isnull(@Type,'') ) from @MasterTable where AAIA_ID = @AAIA
select @Qual1Count = count(distinct isnull(@Model_Name,'')) from @MasterTable where AAIA_ID = @AAIA
select @Qual2Count = count(distinct isnull(@Nameplate,'')) from @MasterTable where AAIA_ID = @AAIA
while @@fetch_status = 0
begin
--------------------------------------------------------------------------------------------------------
select @Qual1Count, @Qual2Count, @Qual3Count
select @AAIA
,@Model_Name
,@Nameplate
,@Type
,@Liters
,@Quarts
,@Filt
,@Note
,@Notes
-----------------------------------------------------------------------------------------------------
fetch next from Processing1 into
@AAIA
,@Model_Name
,@Nameplate
,@Type
,@Liters
,@Quarts
,@Filt
,@Note
,@Notes
end--End Second Loop
Deallocate Processing1
Close Processing1
fetch next from AAIA into
@AAIA
end -- End First loop
deallocate AAIA
close AAIA