ifthenelsenull
Technical User
SQL server 2008
I have two tables that contain three columns that I need.
The first table is the form on which data is entered into a UI and gives me the formname, entereddate and lastchangedtime. This table contains thousands of abbreviations of which I only need 'form1'. This table links to another table that contains values for the form:
Abbreviation, value and lastchangedtime. This table contains thousands of abbreviations of which I only need abc123, abc456 and efg123. The values are a varchar (2500) and the lastchangedtime is actually a date and time field.
This is in the middle of a much larger query pulling in employee information like name, department etc.
What I am currently doing is to alias table two and get isolated values like:
--table 1
Formname = H1.Formname,
enteredDT = H1.entereddate,
Lastchangedtime = H1.Lastchangedtime,
--table 2
t1Abbr = t1.abbr,
t1Value = t1.Value,
t1lastcng = t1.lastchangedtime,
--table 3
t2Abbr = t2.abbr,
t2Value = t2.Value,
t2lastcng = t2.lastchangedtime
--Joins look like
LEFT OUTER JOIN Obs t1 with (NOLOCK)
on H1.assessmentid = t1.assessmentid
and t1.FindingAbbr = 'abc123'
LEFT OUTER JOIN Obs t2 with (NOLOCK)
on H1.assessmentid = HO2.assessmentid
and t2.FindingAbbr = 'abc456'
What I want to occur is that I get
Person_Name, department, formname, t1Abbr, t1Value, t1lastcng, t2Abbr, t2Value, t2lastcng etc...
I've tried to figure it out and it can probably be done with a CTE but I'm not aggregating any of the values and I don't know how to filter for the specific abbreviations I'm looking for.
Any help you can provide is appreciated.
I have two tables that contain three columns that I need.
The first table is the form on which data is entered into a UI and gives me the formname, entereddate and lastchangedtime. This table contains thousands of abbreviations of which I only need 'form1'. This table links to another table that contains values for the form:
Abbreviation, value and lastchangedtime. This table contains thousands of abbreviations of which I only need abc123, abc456 and efg123. The values are a varchar (2500) and the lastchangedtime is actually a date and time field.
This is in the middle of a much larger query pulling in employee information like name, department etc.
What I am currently doing is to alias table two and get isolated values like:
--table 1
Formname = H1.Formname,
enteredDT = H1.entereddate,
Lastchangedtime = H1.Lastchangedtime,
--table 2
t1Abbr = t1.abbr,
t1Value = t1.Value,
t1lastcng = t1.lastchangedtime,
--table 3
t2Abbr = t2.abbr,
t2Value = t2.Value,
t2lastcng = t2.lastchangedtime
--Joins look like
LEFT OUTER JOIN Obs t1 with (NOLOCK)
on H1.assessmentid = t1.assessmentid
and t1.FindingAbbr = 'abc123'
LEFT OUTER JOIN Obs t2 with (NOLOCK)
on H1.assessmentid = HO2.assessmentid
and t2.FindingAbbr = 'abc456'
What I want to occur is that I get
Person_Name, department, formname, t1Abbr, t1Value, t1lastcng, t2Abbr, t2Value, t2lastcng etc...
I've tried to figure it out and it can probably be done with a CTE but I'm not aggregating any of the values and I don't know how to filter for the specific abbreviations I'm looking for.
Any help you can provide is appreciated.