TheBugSlayer
Programmer
I have a CASE and a SPECIMEN table with a one-to-many relationship. One case can have more than one specimen. The specimen has a pipe-separated ClinicalConditions field. I need to write a query that returns a row for each condition, along with some other columns from both tables.
I have writen obtained a function that splits a column given a separator but the database that I use is hosted by another company and it is going to take them about two months to implement my custom function.
In the meantime I NEED to write the query and modify an existing report.
My problem is how to build the functions body into my query.
Here is the gut of the function:
My query looks like this
Very simple.
So if it returns a row like this
I want the new query to give me
I am working on a solution for this and other situations. In the meantime if you have an idea how to best implement it let me know. I will post what I come up with.
Thanks in advance.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
I have writen obtained a function that splits a column given a separator but the database that I use is hosted by another company and it is going to take them about two months to implement my custom function.
In the meantime I NEED to write the query and modify an existing report.
My problem is how to build the functions body into my query.
Here is the gut of the function:
Code:
DECLARE @textXML XML;
SELECT @textXML = CAST('<d>' + REPLACE('ROG-12/XYZ|ROG-4/XYZ', '|', '</d><d>') + '</d>' AS XML);
SELECT T.split.value('.', 'nvarchar(max)') AS data
FROM @textXML.nodes('/d') T(split)
My query looks like this
Code:
SELECT C.ObjectID,
S.ClinicalConditions
FROM CaseTable C
JOIN SpecimenTable S ON S.[Case] = C.ObjectID
WHERE C.Number = 'CASE20120006'
So if it returns a row like this
Code:
ObjectID ClinicalConditions
71823189 ROG-12/XYZ|ROG-4/XYZ
I want the new query to give me
Code:
ObjectID ClinicalConditions
71823189 ROG-12/XYZ
71823189 ROG-4/XYZ
I am working on a solution for this and other situations. In the meantime if you have an idea how to best implement it let me know. I will post what I come up with.
Thanks in advance.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)