SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 07/26/2010 :  04:54:50  Show Profile  Reply with Quote

SELECT  "Result Date", "Result", "Test","Group",RESULT_ID FROM ( 
        SELECT TOP 10 * FROM ( 
                        SELECT TOP 10 RESULTS_DATE_TIME AS "Result Date"  ,RESULT as "Result",TEST_NAME as "Test", RESULTS_DATE_TIME as ENC_DATE,RESULT_ID,LAB_GROUP_NAME as "Group"  FROM ( 
                                    SELECT RESULTS_DATE_TIME,TEST_NAME,cast(RESULTS as varchar(4000)) as RESULT,LAB_GROUP_NAME,RESULT_ID from EMRVWNUMLABRESULTS NLR  
                                    INNER JOIN EMRENCOUNTERDETAILS ED ON ED.PARENT_ENCOUNTER_ID = NLR.PARENT_ENCOUNTER_ID  where ED.IS_SAVE_FOR_LATER IN (0,4) AND  NLR.PATIENT_ID='210330' 
                                    UNION 
                                    SELECT RESULTS_DATE_TIME,TEST_NAME,cast(RESULTS as varchar(4000)) as RESULT,LAB_GROUP_NAME,RESULT_ID from EMRVWTextualLabResults NLR  
                                    INNER JOIN EMRENCOUNTERDETAILS ED ON ED.PARENT_ENCOUNTER_ID = NLR.PARENT_ENCOUNTER_ID  where ED.IS_SAVE_FOR_LATER IN (0,4)  AND NLR.PATIENT_ID='210330' 
                                   UNION 
                                   SELECT RESULTS_DATE_TIME,TEST_NAME,RESULTS ,LAB_GROUP_NAME,RESULT_ID from EMRVWTextualLabResults where  PATIENT_ID='210330' AND PARENT_ENCOUNTER_ID IS NULL  
                                   UNION 
                                   SELECT RESULTS_DATE_TIME,TEST_NAME,RESULTS ,LAB_GROUP_NAME,RESULT_ID from EMRVWNUMLABRESULTS where  PATIENT_ID='210330' AND PARENT_ENCOUNTER_ID IS NULL   
                        )TEMP1 
                                    ORDER BY RESULT_ID ASC  
            )tbl1 ORDER BY  RESULT_ID DESC  
)tbl2 ORDER BY  RESULT_ID ASC





hi now i want in above query where testname should come for all result date colmn

for example like

testname 22-01-2010 23-01-2010 24-01-2010 result group result_id


this is just like
Split Column Data Into Multiple Lines depending on result date column values

Edited by - rajasekhar857 on 07/26/2010 04:59:02

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 07/26/2010 :  05:48:07  Show Profile  Reply with Quote
hi how to achieve the above one by

row value to column name in SQL using dynamic sql in sql server 2005
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 07/26/2010 :  06:14:12  Show Profile  Reply with Quote
hi how to achieve it using pivot query can u please help me out in this..
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000