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 |
oasis1
Starting Member
35 Posts |
Posted - 2014-05-14 : 18:41:54
|
Aloha, I am trying to check for compliance on whether questions are being answered properly for specific orders. For example I have a main question with a value of "y" or "n". If yes is answered I then need to check and see if a value is placed in the next 4 rows for that order id. If all are answered then compliant else not. The issues is there are 5 rows total for each order id. How do I go about evaluating each row and then stating the order is compliant. I could use a case statement for each question ID and then max value to get them on one line and run a select with a where clause stating "and" for each column, but was wondering if there is a slicker way of doing this. here's some data the orderID is 12345 for all the below questions. Question answer questionID RIS ORAL CONTRAST WHO ADMINISTERED Dude, The 1050428 RIS ORAL CONTRAST TYPE Water 1050429 RIS ORAL CONTRAST AMOUNT 750 1050430 RIS ORAL CONTRAST ALLERGY N 101081 RIS ORAL CONTRAST Y 101080Any help always appreciated :-) Thx Brew |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-05-15 : 11:33:08
|
How do you determine a "main question?" There is no concept of Next row in SQL unless you give it an order. However, you might be able group by the Question ID or Order ID (not sure given your sample data) to see if there are 5 rows and one of those 5 rows with an answer of "Y" and "is Primary"?If you want to post some proper sample data that shows compliant and non-complaint data, we can probably help you come up with something reasonably efficient. But, what we have so far seems inadequate to write a query against. |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2014-05-15 : 14:13:22
|
What can your front end do for you?djj |
|
|
|
|
|