|
Hi, Please see the below example data: I need to check that flow goes like this 'VitalsAckByEmr' and then 'PatientSelected' and not 'VitalsAckByEmr' and then 'VitalsAcquired'. Please help me how to write a sql query to cheive it. i should compare value after 'VitalsAckByEmr' to be 'PatientSelected'. Please do the needful. Thanks, Ram
(comments are locked)
|
|
You're attempting to order the data in your query. You need to define something to order it by. From the example above, can you order by the first column? It looks to be ordered in the fashion you need. The query would look something like this (but with your column and table names, since I don't know what they are, I made something up). This query will retrieve the description column from the table, but it will order it by the first column (ID). It will do this in an ascending manner (ASC), counting up. I think I get it, maybe. So the order is by ID still, yes? But you want to compare one value to the next within a result set? You'll need something like this: WITH CompareValues AS (SELECT a.ID, a.Description, ROW_NUMBER() OVER (ORDER BY ID) AS RowOrder FROM dbo.TableA AS a) SELECT cv.ID FROM CompareValue AS cv JOIN CompareValue as cv2 ON cv.RowOrder + 1 = cv2 WHERE cv.Description = 'whatever' and cv2.Description = 'TheOtherthing' Again, bear in mind, I'm dummying this out as psuedo-code so it won't just instantly work in your environment.
Aug 13 '12 at 07:11 PM
Grant Fritchey ♦♦
Wait one. What's not working? What have you tried? I need to see evidence of work on your end before I keep doing free work for you. Are you geting paid to provide this solution? What's my cut if I do all the work?
Aug 13 '12 at 07:53 PM
Grant Fritchey ♦♦
Thanks Fritchey for your time and information shared. I am helping out one of my colleague, so was just playing around to gain some knowledge on the situation he is facing. Anyways appreciate the knowledge you have shared. Thanks, Ram
Aug 13 '12 at 09:04 PM
2ramgopal
(comments are locked)
|
|
Here's an alternative approach. If you've got a unique value to track a particular patient through this system (eg a PatientID), then you might consider this approach: That brings back the following results: If you want to specifically select those PatientID records that don't match the above process, I've added the following records to the @VitalData table: and you can add a and this time, we get: Just an idea, mind... Thanks for the new alternate... added to my learnings Thomas :)
Aug 16 '12 at 03:07 PM
2ramgopal
(comments are locked)
|
|
This might work but would need testing to make sure it scales past 2 records...
(comments are locked)
|

