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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Insert and Select using where clause

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-18 : 12:05:00
I have following code that I need to expand. I need to select only records from t2 where field t2.jde_equipment_hours > 0. I tried to do this but does not seem to work:

insert into #Combined_LaborHrsDetailTable (jobdate, costcode, employeename, equipmentid, equipmentname, jdeequipmenthours) 
select t2.jde_job_date, t2.jde_cost_code, t2.jde_employee_name, t2.jde_equipment_id, t2.jde_equipment_name,
t2.jde_equipment_hours
from #JDE_LaborHrsDetailTable AS t2
where not exists (select * from #Combined_LaborHrsDetailTable AS t1 where t1.jobdate = t2.jde_job_date and
t1.equipmentid = t2.jde_equipment_id and
t1.employeename = t2.jde_employee_name and
t1.eqequipmenthours = t2.jde_equipment_hours and
t2.jde_equipment_hours > 0)

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-18 : 12:39:52
[code]insert into #Combined_LaborHrsDetailTable (jobdate, costcode, employeename, equipmentid, equipmentname, jdeequipmenthours)
select t2.jde_job_date, t2.jde_cost_code, t2.jde_employee_name, t2.jde_equipment_id, t2.jde_equipment_name,
t2.jde_equipment_hours
from #JDE_LaborHrsDetailTable AS t2
where not exists (select * from #Combined_LaborHrsDetailTable AS t1 where t1.jobdate = t2.jde_job_date and
t1.equipmentid = t2.jde_equipment_id and
t1.employeename = t2.jde_employee_name and
t1.eqequipmenthours = t2.jde_equipment_hours
)
AND
t2.jde_equipment_hours > 0[/code]
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-18 : 12:41:51
Thank you buddy, worked fine.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-18 : 13:22:22
np.
Go to Top of Page
   

- Advertisement -