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
 General SQL Server Forums
 New to SQL Server Programming
 Error; please correct the query

Author  Topic 

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-12-27 : 05:38:48
Hai Every One,

am getting error while executing the below query.

update Attendance set Mispunch = 'M'
where CardNo and Dt in
(select CardNo, Dt from #Attendance where (OutCnt = 0 or InCnt = 0))

Thanks in Advance

Suresh Kumar

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-27 : 07:50:38
u should not write subquery like that try this once

update Attendance set Mispunch = 'M'
where CardNo in
(select CardNo from #Attendance where (OutCnt = 0 or InCnt = 0)) and dt in (select dt from #Attendance where (OutCnt = 0 or InCnt = 0))
Go to Top of Page

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-12-27 : 08:50:00
Thnks for ur reply.
Bt its not working.

I want both CardNo and Dt should be checked at same time



Suresh Kumar
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2008-12-27 : 09:16:40
You could join Attendance and #Attendance, something like this:

update Attendance set Mispunch = 'M'
from Attendance a inner join #Attendance b
on a.CardNo = b.CardNo and a.Dt=b.Dt and (b.OutCnt=0 or b.InCnt=0)
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-12-27 : 11:08:30
Use EXISTS.

...
where EXISTS
(select 1 from #Attendance t where (OutCnt = 0 or InCnt = 0) AND t.CardNo = Attendance.CardNo AND t.Dt = Attendance.dt)

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-27 : 11:54:07
isnt this same as

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=116860
Go to Top of Page
   

- Advertisement -