and as a spit can be like this
CREATE PROCEDURE spCountUnits
@itemId int,
@countUnits int OUTPUT
AS
select t1.T1Id, t1.ItemId, t1.UnitId, t1.T1Name, @countUnits = count(*)
from table1 t1
inner join table2 t2 on t1.UnitId = t2.UnitId
where t1.ItemId = @itemId
group by t1.T1Id, t1.ItemId, t1.UnitId, t1.T1Name;
and you can call it like
declare @countUnit int;
exec spCountUnits 2(will be your itemId), @countUnit OUTPUT;
select @countUnit;
Main Topics
Browse All Topics





by: tigin44Posted on 2009-06-27 at 06:53:37ID: 24727706
this query will give you te result
select t1.T1Id, t1.ItemId, t1.UnitId, t1.T1Name, count(*) as CountUnits
from table1 t1
inner join table2 t2 on t1.UnitId = t2.UnitId
where t1.ItemId = 2
group by t1.T1Id, t1.ItemId, t1.UnitId, t1.T1Name