Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi this is Ramesh.

My subQuery sp is
alter proc [dbo].[UDSP_GetPivotTable_Tmf_New_WithAllClients]          
(          
@ClientID int    
)          
as   
SELECT  distinct
        ( SELECT  COUNT(*)   FROM tbl_MainList WHERE  Code = 'Visit';    and ClientID=@ClientID  )   as Visit,
        (SELECT COUNT(*)  FROM tbl_MainList WHERE Code= 'Ptp'   and ClientID=@ClientID)as Ptp
from tbl_MainList where ClientID=@ClientID;  



The Above SP Returns
7 4 6 27 9 379269.00 180283.00 93013.00 128875.00 71626.00
7 4 6 27 9 379269.00 180283.00 93013.00 128875.00 71626.00 Ashish
7 4 6 27 9 379269.00 180283.00 93013.00 128875.00 71626.00 Ayyappa

But the Query returns all the records same but Different Employee Names.

How to pass in Employee name in procedure or Subquery.
suppose i am passing employee name in procedure it will execute only first statement.Second thing gives wrong.
Posted
Updated 29-Mar-12 21:21pm
v2
Comments
Saral S Stalin 30-Mar-12 2:15am    
Can you post the table schema along with sample data and your required output? Subquery may not be the best option here.
Saral S Stalin 30-Mar-12 2:54am    
I understand that this is your second question for the same thing. Abinav suggested to use PIVOT in the first question. Feel like you were not able to understand the PIVOT and use it. I have answered the orignial question with the script you need. Rather than raising a second question, you could have asked for more help in the first.
Rajeev Jayaram 30-Mar-12 3:22am    
Added pre tag.

1 solution

Hi,

What you need to do is:

SQL
alter proc [dbo].[UDSP_GetPivotTable_Tmf_New_WithAllClients]          
(          
@ClientID int    
)          
as   

DECLARE @VISIT INT
DECLARE @PTP INT

SELECT @VISIT=SELECT  COUNT(*)   FROM tbl_MainList WHERE  Code = 'Visit' and ClientID=@ClientID

SELECT @PTP = SELECT COUNT(*)  FROM tbl_MainList WHERE Code= 'Ptp'   and ClientID=@ClientID

SELECT @VISIT AS VISIT, @PTP AS PTP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900