| Author |
Topic |
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 01:54:41
|
| Hi friends,I had two tables Kr_request and kr_requestreplykr_request had fields-reqid,topic,description,abusive,deletedkr_rerquestreply had fields-reqid,topic,description,abusive ,deletedselect distinct r.* from kr_request as r join KR_RequestReply rr ON r.ReqId=rr.ReqId where r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%' and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0here i am getting the correct results but this condition is not working - rr.Abusive = 0 and r.Abusive = 0.i am getting rr.Abusive = 1 and r.Abusive = 1 results also. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 01:58:58
|
try like belowselect distinct r.* from kr_request as r join KR_RequestReply rr ON r.ReqId=rr.ReqId where (r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0 |
 |
|
|
Jason100
Starting Member
34 Posts |
Posted - 2008-11-10 : 01:59:39
|
| SELECT r. FROM ( SELECT * FROM KR_RequestReply WHERE Abusive = 0 AND Deleted =0 ) rr JOIN ( SELECT * FROM kr_request WHERE Abusive = 0 AND Deleted =0 ) r ON r.ReqId=rr.ReqId where r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%' |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 04:30:54
|
| Thank you all ,I got the answer |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 05:18:52
|
| Sorry Guys ,I need a small change in the query.select distinct r.* from kr_request as r join KR_RequestReply rr ON r.ReqId=rr.ReqId where (r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0here we are checking r.ReqId=rr.ReqId so i am getting the results for only the requests which are all replied .i need the request details eventhough it was not replied. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 05:25:31
|
| [code]select distinct r.* from kr_request as r left join KR_RequestReply rr ON r.ReqId=rr.ReqId where (r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0[/code] |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 05:38:03
|
| i am not getting the result |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 05:40:10
|
try this tooselect distinct r.* from kr_request as r left join KR_RequestReply rr ON r.ReqId=rr.ReqId on (r.topic like '%test%' or r.Description like '%test%' or rr.Description Like '%test%' or rr.topic like '%test%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0 if not working, then post some sample data |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 05:56:30
|
| Getting error as Incorrect syntex near on.Sample Data:kr_requestreqid Topic Description abusive deleted 1 Test 1 Test is going1 0 02 Test 2 Test is going2 0 03 Test 3 Test is going3 0 04 complete Work 0 05 Test 4 Test is going4 0 0RepId reqid Topic Description abusive deleted 1 2 Sample1 Sample Test1 0 02 3 Sample2 Sample Test 2 0 03 1 Sample3 Sample Test 3 0 04 1 Sample4 Sample Test 4 0 05 5 Test Completed 0 0When i search using this query select distinct r.* from kr_request as r left join KR_RequestReply rr ON r.ReqId=rr.ReqId on (r.topic like '%Complete%' or r.Description like '%Complete%' or rr.Description Like '%Complete%' or rr.topic like '%Complete%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0I am getting the result for only reqid=5 but not for reqid=4 since for reqid=4 no one was replied. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 05:59:42
|
Try thisselect distinct r.* from kr_request as r left join KR_RequestReply rr ON r.ReqId=rr.ReqId AND (r.topic like '%Complete%' or r.Description like '%Complete%' or rr.Description Like '%Complete%' or rr.topic like '%Complete%') and rr.Abusive = 0 and rr.Deleted= 0 and r.Abusive = 0 and r.Deleted=0 |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-11-10 : 06:33:14
|
| No i am not getting the results |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 06:55:06
|
| [code]declare @kr_request table(reqid int,Topic varchar(30),Description varchar(20),abusive bit,deleted bit)insert into @kr_request select 1, 'Test 1', 'Test is going1', 0, 0 union allselect 2, 'Test 2', 'Test is going2', 0 ,0 union allselect 3, 'Test 3' ,'Test is going3', 0 ,0 union allselect 4 ,'complete', 'Work', 0, 0 union allselect 5 ,'Test 4' ,'Test is going4', 0, 0declare @KR_RequestReply table(RepId int,reqid int,Topic varchar(50),Description varchar(50),abusive bit,deleted bit)insert into @KR_RequestReplyselect 1, 2, 'Sample1', 'Sample Test1', 0, 0 union allselect 2, 3, 'Sample2', 'Sample Test 2', 0, 0 union allselect 3, 1, 'Sample3', 'Sample Test 3', 0, 0 union allselect 4, 1, 'Sample4', 'Sample Test 4', 0, 0 union allselect 5, 5, 'Test', 'Completed', 0 ,0select distinct r.* from @kr_request as r left join @KR_RequestReply rr ON r.ReqId=rr.ReqId WHERE (r.topic like '%Complete%' or r.Description like '%Complete%' or rr.Description Like '%Complete%' or rr.topic like '%Complete%') and isnull(rr.Abusive,0) = 0 and isnull(rr.Deleted,0)= 0 and r.Abusive = 0 and r.Deleted=0output----------------------------------------reqid Topic Description abusive deleted4 complete Work 0 05 Test 4 Test is going4 0 0 [/code] |
 |
|
|
|