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 |
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-29 : 03:21:57
|
| I have two table: Job and JobapplyRecordWhen i use the left join statement, i get JobID JobApplyRecordID7.............null8....... 68....... 78....... 89..............10However, my expected result: I only need to know whether recordID is null or not For exampleJobID JobApplyRecordID7.............null8....... "exist"9..............10How to do this?be a hardworking people!! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-29 : 03:36:02
|
| Do you want to get only one record for each job id?What do you mean by exists for 8?Post the query you used?MadhivananFailing to plan is Planning to fail |
 |
|
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-29 : 03:44:11
|
| sorry , i forget to post the query select JobID, JObApplyRecordIDfrom job left join jobapplyrecordThere may/may not have apply record for each job.My purpose is to know whether a job have apply record(no matter the no), if yes, then show exist or sth in the cell.be a hardworking people!! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-29 : 03:48:55
|
| Try thisselect JobID, case when JObApplyRecordID is not null then 'Exists' end from job left join jobapplyrecordMadhivananFailing to plan is Planning to fail |
 |
|
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-29 : 03:56:51
|
| My desired output is that the jobid is distinctEGJobID JobApplyRecordID7.............null8....... "exist"9..............10But your query result into JobID JobApplyRecordID7.............null8....... "exist"8....... "exist"8....... "exist"9..............10I find i cannot use the "distinct". How to solve this ?be a hardworking people!! |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-08-29 : 03:59:17
|
| [code]select JobID, case (select count(JObApplyRecordID) from jobApplyRecord where jobApplyRecord.jobid = job.jobid) when 0 then null when 1 then cast(jobapplyrecordid as varchar(11)) else 'Exist' endfrom job[/code] |
 |
|
|
acdacd
Yak Posting Veteran
63 Posts |
Posted - 2005-08-29 : 04:16:54
|
| Thanks!Only distinct(Jobid) is need at this case!be a hardworking people!! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-29 : 04:17:29
|
| Then use this queryselect Distinct JobID, case when JObApplyRecordID is not null then 'Exists' end from job left join jobapplyrecordMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|