Author |
Topic |
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 04:01:04
|
Hi all Here how can i achieve tree view in this scenarioFor Example Acute Patient (grand Parent) CPT (Parent) 1101 1102 RevCode (Parent) AC36 AC37 In some case there will be no grand Parent then parent should be act as Grand parent. For Grand Parent i gave row_number to get ID's basing on that i need to get tree viewhere is my query SELECT DISTINCT top 5 Sno = ROW_NUMBER() OVER ( ORDER BY ECTCodeDescription DESC ), ECTCodeDescription, CSEC.ECTHedisCodeTypeCode, ECT.ECTHedisTableName, ECTCodeFROM CodeSetHEDIS_ECTCode ECINNER JOIN CodeSetECTHedisTable ECT ON ECT.ECTHedisTableID = EC.ECTHedisTableIDINNER JOIN CodeSetECTHedisCodeType CSEC ON CSEC.ECTHedisCodeTypeID = EC.ECTHedisCodeTypeIDWHERE ECT.ECTHedisTableID = 29 --AND ECTCodeDescription = 'Nonacute inpatient'GROUP BY ECTCodeDescription, ECTCode, ECTHedisTableName, CSEC.ECTHedisCodeTypeCode my resut set is coming like this Sno ECTCodeDescription ECTHedisCodeTypeCode ECTCode 1 Outpatient CPTCODE 0510 2 Outpatient CPTCODE 0511 3 NonAcute RevCode AC36 4 NonAcute RevCode AC36 5 NonAcute RevCode AC36 How can i get output like on the above query : Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6 suggest meP.V.P.MOhan |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-24 : 04:38:43
|
Can you post sample data in consumable format and also clear and exact output for that data....For this kind of hierarchical queries you can use of CTEs in sql server--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 04:39:48
|
plz check my updated questionP.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 05:17:58
|
yeah chandu this one his correct data from my original tables Sno ECTCodeDescription ECTHedisCodeTypeCode ECTCode 1 Outpatient CPTCODE 0510 2 Outpatient CPTCODE 0511 3 NonAcute RevCode AC36 4 NonAcute RevCode AC36 5 NonAcute RevCode AC36 and my required output Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6 P.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-24 : 05:19:47
|
No yar....I asked for sample data of 3 tables CodeSetHEDIS_ECTCode, CodeSetECTHedisTable and CodeSetECTHedisCodeType--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 05:38:52
|
okay i will post you with in few minutesP.V.P.MOhan |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 05:52:45
|
CodeSetHEDIS_ECTCode Sno ECTCodeDescription ECTHEDISCODETYPEID ECTHedisTableID1 Outpatient 4 11 2 Nonacute inpatient 2 233 ED 6 114 Acute inpatient 9 29 CodeSetECTHedisTable and CodeSetECTHedisCodeType keys referenced to table CodeSetHEDIS_ECTCodeCodeSetECTHedisTableECTHedisTableID ECTHedisTableName1 AAB-A2 AAB-B3 AAB-C29 AAB-D4 ABA-A CodeSetECTHedisCodeTypeECTHedisCodeTypeID ECTHedisCodeTypeCode1 CPT2 CPT-CAT-II3 CPT-Mod4 REVCODE5 ICD9-Diag P.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-24 : 07:19:18
|
How come the ID of SNO >=7 are 6?--Check this one DECLARE @tab TABLE( Sno INT, ECTCodeDescription VARCHAR(30), ECTHedisCodeTypeCode VARCHAR(30), ECTCode VARCHAR(30))INSERT INTO @tabSELECT 1, 'Outpatient', 'CPTCODE', '0510' union allSELECT 2, 'Outpatient', 'CPTCODE', '0511' union allSELECT 3, 'NonAcute', 'RevCode', 'AC36' union allSELECT 4, 'NonAcute', 'RevCode', 'AC37' union allSELECT 5, 'NonAcute', 'RevCode', 'AC38'/*How can i get output like on the above query : Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6*/SELECT DISTINCT Val ,CASE WHEN K = 'ECTCodeDescription' THEN 0 ELSE DENSE_RANK() OVER(ORDER BY K DESC, Val) END ID FROM @tab UNPIVOT (Val For K IN (ECTCodeDescription, ECTHedisCodeTypeCode, ECTCode)) UORDER BY ID --Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 07:51:50
|
hey chandu it is giving result but not in expected way i getting output like this by using your given query Val IDNonAcute 0Outpatient 0CPTCODE 1RevCode 20510 50511 6AC36 7AC37 8AC38 9 but i need to show like this one Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6 just observe the difference between both CPTCODE(0510,0511) anbd revcode (AC36,AC37,AC38)but it is giving like this CPTCODE,revcode,0510,0511AC36,AC37,AC38suggest meP.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-24 : 08:08:03
|
Hello,I too know that result...I need clarification on ID column... how it has 6 for these three values (AC36, AC37, AC38)Do you know another thing you didn't give the column ECTCode in your sample data....--Chandu |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-24 : 08:23:52
|
result is coming like this Val IDNonAcute0Outpatient0CPTCODE 1RevCode 20510 50511 6AC36 7AC37 8AC38 9 i need to get like this Val IDNonAcute0Outpatient0CPTCODE 10510 50511 6RevCode 2AC36 7AC37 8AC38 9 P.V.P.MOhan |
|
|
namman
Constraint Violating Yak Guru
285 Posts |
Posted - 2013-05-24 : 12:16:37
|
Hi mohan123 Look like the important column in expected output is ID.But the latest one is different from the first. So which one do you want?quote: How can i get output like on the above query : Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6i need to get like this Val IDNonAcute0Outpatient0CPTCODE 10510 50511 6RevCode 2AC36 7AC37 8AC38 9
Also, what is the version (2000, 2005, 2008 or 2012) ? |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2013-05-27 : 00:41:57
|
this the data for example DECLARE @tab TABLE( Sno INT, ECTCodeDescription VARCHAR(30), ECTHedisCodeTypeCode VARCHAR(30), ECTCode VARCHAR(30))INSERT INTO @tabSELECT 1, 'Outpatient', 'CPTCODE', '0510' union allSELECT 2, 'Outpatient', 'CPTCODE', '0511' union allSELECT 3, 'NonAcute', 'RevCode', 'AC36' union allSELECT 4, 'NonAcute', 'RevCode', 'AC37' union allSELECT 5, 'NonAcute', 'RevCode', 'AC38' but i need to show like this one Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6 my SSMS version is 2008R2P.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-27 : 02:59:16
|
[code]--Is that ID column for the purpose of sorting only....? If yes you can do like the belowDECLARE @tab TABLE( Sno INT, ECTCodeDescription VARCHAR(60), ECTHedisCodeTypeCode VARCHAR(60), ECTCode VARCHAR(60))INSERT INTO @tabSELECT 1, 'Outpatient', 'CPTCODE', '0510' union allSELECT 2, 'Outpatient', 'CPTCODE', '0511' union allSELECT 3, 'NonAcute', 'RevCode', 'AC36' union allSELECT 4, 'NonAcute', 'RevCode', 'AC37' union allSELECT 5, 'NonAcute', 'RevCode', 'AC38'/*How can i get output like on the above query : Sno Names ID 1 Outpatient NULL 2 NonAcute NULL 3 CPTCODE 1 4 0510 3 5 0511 3 6 RevCode 2 7 AC36 6 8 AC37 6 9 AC38 6*/SELECT DISTINCT CASE WHEN K = 'ECTCodes' THEN ECTCode ELSE Val END Val ,CASE WHEN K = 'ECTCodeDescription' THEN 0 else DENSE_RANK() OVER(ORDER BY val) END RNFROM (SELECT *, CAST (ECTHedisCodeTypeCode+' '+ ECTCode AS VARCHAR(60))AS ECTCodes FROM @tab) TUNPIVOT (Val For K IN (ECTCodeDescription, ECTHedisCodeTypeCode, ECTCodes)) UORDER BY RN[/code]--Chandu |
|
|
|