ASPDEV
asked on
Get Rows affected Count using SQL Query
Hello Experts,
I'm working on a SQL Query, where I need to count the records affetced with query i.e I need rows count.
I need the count of rows affected from the above query. For that , I tried this:
But I don't want to do it twice ,to get the count and Result set.
I'm working on a SQL Query, where I need to count the records affetced with query i.e I need rows count.
SELECT (VTC.CODE) as [CODES] , VTC as VID , isnull(EMP.TYPE,'GENERAL') as [TYPE]
FROM EMP V LEFT OUTER Join VTC
ON V.[ID] = VTC.[ID]
LEFT OUTER JOIN dbo.DEPT AS D
ON vtc.Code = D.Code
I need the count of rows affected from the above query. For that , I tried this:
--ResultSet
SELECT (VTC.CODE) as [CODES] , VTC as VID , isnull(EMP.TYPE,'GENERAL') as [TYPE]
FROM EMP V LEFT OUTER Join VTC
ON V.[ID] = VTC.[ID]
LEFT OUTER JOIN dbo.DEPT AS D
ON vtc.Code = D.Code
--Row Count
select Count(*) from (
SELECT (VTC.CODE) as [CODES] , VTC as VID , isnull(EMP.TYPE,'GENERAL') as [TYPE]
FROM EMP V LEFT OUTER Join VTC
ON V.[ID] = VTC.[ID]
LEFT OUTER JOIN dbo.DEPT AS D
ON vtc.Code = D.Code) as T
But I don't want to do it twice ,to get the count and Result set.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
ASPDEV