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 |
ccbuilder
Starting Member
17 Posts |
Posted - 2012-09-17 : 23:37:05
|
I have a question similar to this [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=178040[/url] post but with different criteria and cannot get it to work :(My table structure is as follows:aRowID int auto pkTID int not null fkSeq int not nullUID varchar(30) not nullDTS_Assigned datetime not nullDTS_Approved datetime not nullHow can I get a query of items awaiting approval for the following janedoe using the following data:9 100 0 jdoe '9/17/2012 9:07:56 AM' '9/17/2012 1:51:59 PM'15 100 1 janedoe '9/17/2012 1:51:59 PM' NULL21 120 0 janie NULL NULL25 120 1 janedoe NULL NULLthe query should pick up jane doe at TID 100 I cannot get a query to work. Please note that seq items are sequential so that janedoe may be found either at seq 1 or 2 or XI hope this makes sense, thanks in advance for the help. |
|
ccbuilder
Starting Member
17 Posts |
Posted - 2012-09-21 : 01:10:46
|
What about using a query to get all items where approver is located?Select * from ApprovalsWhere UID='janedoe'This will give the rows where janedoe is presentThis query will give:15 100 1 janedoe '9/17/2012 1:51:59 PM' NULL25 120 1 janedoe NULL NULLBased on the results, only janedoe at TID 100 should be returnedAt this point how about cursors to traverse thru the records returned by the above query?I just don't know how to do it?Your help is greatly appreciated. |
|
|
ccbuilder
Starting Member
17 Posts |
Posted - 2012-09-22 : 00:29:12
|
I think it's almost close, i currently have:SELECT DISTINCT t1.aRowID, t1.Seq, t1.TID, t1.UID, t1.RowStatus FROM Assignments t1CROSS APPLY(SELECT DTS_Approved FROM Approvals WHERE TID = t1.TID AND aRowID < t1.aRowID)t2WHERE t2.DTS_Approved IS NOT NULLAND t1.DTS_Approved IS NULLAND t1.UID = 'janedoe' and RowStatus='Sthis gives me almost what i need except that janedoe is still able to see TID 120 even though is not her turn to approve :(21 120 0 janie NULL NULL25 120 1 janedoe NULL NULLhow can I modify this query to that she is only able to see TID when janie has approved? |
|
|
|
|
|