Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
gnethery
Starting Member
1 Post |
Posted - 2009-06-19 : 15:45:28
|
I could use help with the following script. The goal is to get all the Guideline_criteria in one row for each unique Account_Number and Assgn_Shift_Summary_ID combination.Here is the data:DECLARE @temp TABLE (Account_Number CHAR(13), Assgn_Shift_Summary_ID char(10), Guideline_Criteria VARCHAR(255)) INSERT INTO @tempSELECT 'BRK5016980228', '1009175' , 'CRT patient that remains on the unit.' UNION ALLSELECT 'BRK5016980228', '1009175' , 'Epilepsy requiring monitoring. (2:1 ratio)' UNION ALLSELECT 'BRK5017167938', '1008775' , 'Dialysis or bedside pheresis– day of.' UNION ALLSELECT 'BRK5017167938', '1008775' , 'Moribund/DNRs requiring >30 minutes or with large family.' UNION ALLSELECT 'BRK5016980228', '1008775' , 'Physiological instability is LIFE-THREATENING (codes, status asthmaticus, status epilepticus).' UNION ALLSELECT 'BRK5016980228', '1008775' , 'Care off unit > 1 hour (e. g. surgery, transport)' UNION ALLSELECT 'BRK5016980228', '1009175' , 'Seizure patient actively seizing/status epileptus' SELECT * FROM @temp This returns:Account_Number,Assgn_Shift_Summary_ID,Guideline_CriteriaBRK5016980228,1009175,CRT patient that remains on the unit.BRK5016980228,1009175,Epilepsy requiring monitoring. (2:1 ratio)BRK5017167938,1008775,Dialysis or bedside pheresis– day of.BRK5017167938,1008775,Moribund/DNRs requiring >30 minutes or with large family.BRK5016980228,1008775,Physiological instability is LIFE-THREATENING (codes, status asthmaticus, status epilepticus).BRK5016980228,1008775,Care off unit > 1 hour (e. g. surgery, transport)BRK5016980228,1009175,Seizure patient actively seizing/status epileptusWhat I would like to have returned is:Account_Number,Assgn_Shift_Summary_ID,Guideline_CriteriaBRK5016980228,1009175,CRT patient that remains on the unit. ; Epilepsy requiring monitoring. (2:1 ratio) ; Seizure patient actively seizing/status epileptusBRK5017167938,1008775,Dialysis or bedside pheresis– day of. ; Moribund/DNRs requiring >30 minutes or with large family.BRK5016980228,1008775,Physiological instability is LIFE-THREATENING (codes, status asthmaticus, status epilepticus). ; Care off unit > 1 hour (e. g. surgery, transport)For each unique combination of Account_Number and Assgn_Shift_Summary_ID return all Guideline_criteria seperated by (space);(space).Thanks in advance for any guidance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-20 : 02:44:53
|
use a UDF like belowCREATE FUNCTION ConcatValues(@AccntNo varchar(20))RETURNS Varchar(8000)ASBEGINDECLARE @RetVal Varchar(8000)SELECT @RetVal=COALESCE(@RetVal,'') + Guideline_Criteria + ';'FROM YourTableWHERE Account_Number=@AccntNoRETURN @RetValENDGOthen use it like thisSELECT DISTINCT Account_Number,Assgn_Shift_Summary_ID,dbo.ConcatValues(Account_Number) AS Guideline_CriteriaFROM YourTable |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|