sql server - count of multiple columns in stored procedure -
stored procedure this:
alter procedure [dbo].[driverperformance] @ecode nvarchar(50), @startdate datetime, @enddate datetime begin select e.ecode, cast(q.dtime date) date , e.ename, count(q.ecode) cntecode employeemaster_tbl e join transaction_tbl q on e.ecode = q.ecode q.ecode=@ecode , dtime >= '' + @startdate +'' , dtime <= ''+@enddate +'' group e.ecode, e.ename, cast(q.dtime date) order cast(q.dtime date)--e.ecode desc end
this working fine.in getting count of [(q.ecode)] perferct.i have 1 more field in transactiontable name(delecode).i want take count of(delecode) same way.sam way means how taking count of ecode have take count of delecode aslos.so changes have make in current stored procedure..while executing getting out put this: want 1 more column cntdelcode in want show count of delecode
something gives user choice of whether query ecode or delecode:
alter procedure [dbo].[driverperformance] @code nvarchar(50), @startdate datetime, @enddate datetime, @test varchar(1) if @test = 1 begin select e.ecode, cast(q.dtime date) date , e.ename, count(q.ecode) cntecode employeemaster_tbl e join transaction_tbl q on e.ecode = q.ecode q.ecode=@code , dtime >= '' + @startdate +'' , dtime <= ''+@enddate +'' group e.ecode, e.ename, cast(q.dtime date) order cast(q.dtime date)--e.ecode desc end else begin select e.delecode, cast(q.dtime date) date , e.ename, count(q.delecode) cntcode employeemaster_tbl e join transaction_tbl q on e.delecode = q.delecode q.delecode=@code , dtime >= '' + @startdate +'' , dtime <= ''+@enddate +'' group e.delecode, e.ename, cast(q.dtime date) order cast(q.dtime date)--e.ecode desc end end
this untested, can see going. input allows user choose field test on.
Comments
Post a Comment