Author |
Topic |
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-02-21 : 10:13:37
|
Hello all,i have query where for Customer id i will show counts...Select B.Cust_ID,B.ProfileOwnerEmpID,LAc.ProfileStatusID from Emp_Details E join Cust_BasicInfo B on E.EmpID=B.ProfileOwnerEmpID join Cust_Login LAc on LAc.Cust_ID=B.Cust_IDwhere E.EmpID=2 [CODE]Cust_ID ProfileOwnerEmpID ProfileStatusID62 2 5664 2 5731 2 5422 2 5432 2 5516 2 5440 2 56[/code]but i need to get out put like this one : [CODE]Profile 56==ProfileStatusID 57==ProfileStatusID 54==ProfileStatusID2 count 2 count 2 count 2 [/code]the result should come like thisP.V.P.MOhan |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-21 : 12:40:20
|
[code]SELECT *FROM(Select B.Cust_ID,LAc.ProfileStatusID from Emp_Details E join Cust_BasicInfo B on E.EmpID=B.ProfileOwnerEmpID join Cust_Login LAc on LAc.Cust_ID=B.Cust_IDwhere E.EmpID=2) sPIVOT (COUNT(Cust_ID) FOR ProfileStatusID IN ([56],[57],[54]))P[/code] |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-02-22 : 01:19:10
|
How to give alias names for [56],[57],[54] this column headers.they are coming after using pivot...need to come like this 56 as firstcount,57 as Second Count,54 as third countP.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-22 : 02:24:44
|
SELECT Cust_ID, ProfileStatusID, [56] AS firstCount, [57] AS secondCount, [54] AS thirdCountFROM(Select B.Cust_ID,LAc.ProfileStatusID from Emp_Details E join Cust_BasicInfo B on E.EmpID=B.ProfileOwnerEmpID join Cust_Login LAc on LAc.Cust_ID=B.Cust_IDwhere E.EmpID=2) sPIVOT (COUNT(Cust_ID) FOR ProfileStatusID IN ([56],[57],[54]))P--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-02-22 : 02:35:43
|
while executing this query i am getting error as 'The multi-part identifier'B.Cust_ID, LAc.ProfileStatusID i gave like this entire query baSED ON joins.so it is giving error how to over come this if i remove both in select query result coming fine.ProfileOwnerEmpIDProfileOwnerEmpID 56 57 542 2 1 3 [CODE]firstCount secondCount thirdCount2 1 3[/code]how i can get first output with out error 'The multi-part identifier'P.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-22 : 02:42:10
|
[code]SELECTProfileOwnerEmpID, [56] AS firstCount, [57] AS secondCount, [54] AS thirdCountFROM(Select B.Cust_ID,LAc.ProfileStatusID, B.ProfileOwnerEmpIDfrom Emp_Details E join Cust_BasicInfo B on E.EmpID=B.ProfileOwnerEmpID join Cust_Login LAc on LAc.Cust_ID=B.Cust_IDwhere E.EmpID=2) sPIVOT (COUNT(Cust_ID) FOR ProfileStatusID IN ([56],[57],[54]))P[/code]EDIT: Red Marked--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-02-22 : 02:48:25
|
getting the same error even if i give ProfileOwnerEmpID,Cust_ID if i remove the those columns getting query executed....[56] AS firstCount, [57] AS secondCount, [54] AS thirdCount these three are showing..... along with this three columns i need to show ProfileOwnerEmpID also....suggest meP.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-22 : 03:35:03
|
Check my previous post.... I have edited--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-02-22 : 04:00:16
|
thanks chandu....why i missed this one????.....P.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-22 : 04:17:40
|
quote: Originally posted by mohan123 thanks chandu....why i missed this one????.....P.V.P.MOhan
WelcomeWhile pivoting you can select the columns that are in inner query....--Chandu |
|
|
|