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 |
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-11-18 : 01:17:05
|
RequestTblRequestID userid 97 z100 98 z100 99 z100 100 m125 101 m125 102 e65 103 f789 104 k75 105 k75TaskTblTaskID RequestID1 972 983 974 975 986 997 1008 1019 10210 104TaskUserAssignedTUID TaskID Submitted150 1 1151 2 1152 3 1153 4 1154 5 1155 6 1156 7 0157 8 1158 10 1Relation: Requesttbl,Tasktabl:Requestid Tasktbl,TaskuserAssignedtbl: TaskidCase 1:If input Parameter passed as z100First it will get the Requestid from RequestTbl for z100,this case requestid is : 97,98,99.ThenIn Tasktbl,to find the Taskid for 97(1,3,4) to find the Taskid for 98(2,5) to find the Taskid for 99 (6)ThenIn TaskUserAssigned tbl, To see the Submitted column as 1 for taskid is 1 To see the Submitted column as 1 for taskid is 3 To see the Submitted column as 1 for taskid is 4 To see the Submitted column as 1 for taskid is 2 To see the Submitted column as 1 for taskid is 5 To see the Submitted column as 1 for taskid is 6if this is the case,Return 1case 2:Parameter : m125for this case requesid :100,101Tasktbl:to find the Taskid for 100(7) to find the Taskid for 101(8) TaskUserAssignedTbl, To see the Submitted column as 0 for taskid is 7 To see the Submitted column as 1 for taskid is 8will hvae to Return 0 (Reason : all the taskid should be 1,if any 0 means,return 0)Case 3:Parameter : e65First it will get the Requestid from RequestTbl for e65,this case requestid is : 102.ThenIn Tasktbl,to find the Taskid for 102(9) In TaskUserAssigned tbl,No Task,I mean ,for Taskid 9 is not there..so this case Return 0.Case 4: f789First it will get the Requestid from RequestTbl for f789,this case requestid is : 103.ThenIn Tasktbl,for requets id 103,no task is there..So return 0.Case 5: k75First it will get the Requestid from RequestTbl for f789,this case requestid is : 104,105.ThenIn Tasktbl,to find the Taskid for 104(10) to find the Taskid for 105.(No Task is there)..even though 104 requestid,Task no 10,TaskUserAssigned tbl for task no 10,submitted column is 1 but no task created for 105.So return 0.Only for Case 1,Return 1,rest of the cases return 0.please any sample query..any help much appreciated..if iam unclear,kindly please reply |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-18 : 07:20:10
|
[code]SELECT CASE WHEN COUNT(t.TaskID) = COUNT(DISTINCT tua.TaskID) THEN 1 ELSE 0 ENDFROM RequestTbl rINNER JOIN TaskTbl tON t.RequestID= r.RequestIDLEFT JOIN TaskUserAssigned tuaON tua.TaskID = t.TaskIDAND Submitted = 1WHERE r.userid=@UserID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|