We help IT Professionals succeed at work.

Get Rows affected Count using SQL Query

Medium Priority
544 Views
Last Modified: 2012-05-11
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.

 
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

Open in new window


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

Open in new window


But I don't want to do it twice ,to get the count and Result set.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Awesome!

Thanks,
ASPDEV
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.