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 |
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-04-10 : 00:43:54
|
| I am facing a query problem.i have 2 tables called emp-table and report-table.report table for listing report of employees.following are criterias..1 I want list all reports from report-table2 But no report should have empstatus 53 reports need not necessary to have emp-table reference.ie emp-id reference in emp_table. briefly saying i want all reports from report table,in which no one have empstatus 5 emp-table empid empname empstatus report-tablerepid empid detailsthanks in advance. |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-04-10 : 00:46:24
|
| I am facing a query problem.i have 2 tables called emp-table and report-table.report table for listing report of employees.following are criterias..1 I want list all reports from report-table2 But no report should have empstatus 53 reports need not necessary to have emp-table reference.ie emp-id reference in emp_table.briefly saying i want all reports from report table,in which no one have empstatus 5emp-table empid empnameempstatus report-tablerepid empid detailsthanks in advance. |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-10 : 00:59:03
|
select rt.*from reporttable rtleft join emptable et on et.empid=rt.empid and et.empstatus<>5 elsasoft.org |
 |
|
|
cvipin
Yak Posting Veteran
51 Posts |
Posted - 2008-04-10 : 01:04:40
|
| declare @emp_table Table (empid int, empname varchar(20), empstatus varchar(2))insert into @emp_table values (1, 'EmpName1', '1')insert into @emp_table values (2, 'EmpName2', '2')insert into @emp_table values (3, 'EmpName3', '5')declare @report_table Table (repid int, empid int, details varchar(20))insert into @report_table values (10, 1, 'Report1')insert into @report_table values (11, 2, 'Report2')insert into @report_table values (12, 3, 'Report3')insert into @report_table values (13, 1, 'Report4')insert into @report_table values (14, 4, 'Report5')select repid, rep.empid, details from @report_table rep left outer join @emp_table emp on rep.empid = emp.empid where ISNULL(empstatus, '-1') <> '5' |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-10 : 01:41:15
|
oops, nothing like a little sample data to test with! elsasoft.org |
 |
|
|
|
|
|
|
|