sql server - while fetching count of two column in same table not showing proper count of second column -
my 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 , count(q.delecode) cntdelecode employeemaster_tbl e inner join transaction_tbl q on e.ecode = q.ecode q.ecode=@ecode , dtime between '' + @startdate +'' , ''+@enddate+'' group e.ecode, e.ename, cast(q.dtime date) order cast(q.dtime date)--e.ecode desc end
i passed parameter this: @ecode = 'e003' @startdate = '2013-09-03', @enddate = '2013-09-03'
am getting out put this: cntdelecode getting wrong.(i not getting count of delecode proper) have changed in stored procedure)
for checking count of cntecode worte query this:
select * transaction_tbl dtime >='2013-09-03 00:00:00.000' , dtime <='2013-09-03 23:59:59.000' , ecode='e003'
. getting 27 rows.so understood cntecode count corect. checking count of cntdelecode worte query this:
select * transaction_tbl dtime >='2013-09-03 00:00:00.000' , dtime <='2013-09-03 23:59:59.000' , delecode='e003'
now getting 35 rows..but while executing stored procedure getting 23 rows insetd of getting 35 rows..where stored procedure gone wrong? please me find out
in query 35 rows, counting rows delecode='e0003'
which a different query above query. no wonder results different.
you change query
select e.ecode,cast(q.dtime date) date , e.ename, count(q.ecode) cntecode , (select count(*) transaction_tbl q.ecode=@ecode , dtime between @startdate , @enddate) cntdelecode employeemaster_tbl e ...
Comments
Post a Comment