Note that there are some explanatory texts on larger screens.

plurals
  1. POSelecting from single dataset on multiple columns for a result with combined columns but multiple rows
    primarykey
    data
    text
    <p>This problem hurts my head, probably because the database design itself could be better (such as having a single Column for storing the response to any question with multiple tables to map with multiple records of the same cert id).</p> <p>This is what the table looks like and a sample record that I am trying to query from, essentially:</p> <pre><code>CERTIFICATIONID EMPID Q1_STATUS Q2_STATUS Q3_STATUS Q4_STATUS LAST_UPDATED 223 00001282122 1 0 1 1 2013-11-13 09:45:23.420 </code></pre> <p>What I'd like to make happen with my query in the short term:</p> <pre><code>CERTIFICATIONID EMPID QUESTION ANSWER LAST_UPDATED 223 00001282122 1 1 2013-11-13 09:45:23.420 223 00001282122 2 0 2013-11-13 09:45:23.420 223 00001282122 3 1 2013-11-13 09:45:23.420 223 00001282122 4 1 2013-11-13 09:45:23.420 </code></pre> <p>With these results, getting basically every <em>answer</em> as a result opposed to every <em>certification</em>, I could more easily make the query to generate a report (which would rely on another table which holds things like the Question prompt for a QUESTION id itself) which would look something like:</p> <pre><code>EMPID QUESTIONPROMPT 2013-11-10 2013-11-11 2013-11-12 2013-11-13 2013-11-14 2013-11-15 2013-11-16 00001282122 "Was good morning?" NULL NULL NULL 1 NULL NULL NULL 00001282122 "Was good day?" NULL NULL NULL 0 NULL NULL NULL 00001282122 "Was good evening?" NULL NULL NULL 1 NULL NULL NULL 00001282122 "Was good night?" NULL NULL NULL 1 NULL NULL NULL </code></pre> <p>Hopefully that describes the dilemma I'm faced with. I started to look into Joins, Pivots, etc.. and I'm just not sure what the best approach here would be. I don't really have the option of taking this Certification table, and splitting it out by all cert ids, and another table for question ids, and another table for making a proper many-to-many relationship between the two (a Cert ID may have multiple questions answered by a user in a single cert, and these same questions are also answered by other users and times in other Cert IDs).</p> <p>So what do I do in a scenario like this, having to make a report from a database table that isn't as normalized and relational as it probably ought to be.</p> <p>(edit) P.S- I tried formatting the data into here as best I can, but is there a good way to bring in results from SQL Server into Stack Overflow in a manner that doesn't involve me adding spaces until everything looks somewhat right for next time, both for my own efficiency and for cleanliness?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload