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)
 VERY URGENT

Author  Topic 

nishita_s
Yak Posting Veteran

61 Posts

Posted - 2009-02-23 : 23:34:18
UPDATE SavingsRegister
SET FK_SKSOL_ClientID=Clients.UniqueID
FROM SavingsRegister WITH(NOLOCK)
INNER JOIN Clients WITH(NOLOCK)
ON SavingsRegister.ClientID=Clients.ClientID
WHERE RecordStatus <> 'O' OR RecordStatus <> 'D'

i have lot of data in savingsledger table.
i need to update this table.
in where clause i m using
RecordStatus not in( 'O' , 'D')
is it better than following statement?
RecordStatus <> 'O' OR RecordStatus <> 'D'

raky
Aged Yak Warrior

767 Posts

Posted - 2009-02-23 : 23:44:14
I think both are equal in performance
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-23 : 23:50:40
hi nishita,
it is better to use <> only because in some cases, not in will fails
r use not exists than not in (performance is more for exists than in)
Go to Top of Page

nishita_s
Yak Posting Veteran

61 Posts

Posted - 2009-02-24 : 00:28:07
hi bklr
How to use not exists in following statement
UPDATE SavingsRegister
SET FK_SKSOL_ClientID=Clients.UniqueID
FROM SavingsRegister WITH(NOLOCK)
INNER JOIN Clients WITH(NOLOCK)
ON SavingsRegister.ClientID=Clients.ClientID
WHERE RecordStatus <> 'O' OR RecordStatus <> 'D'
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-24 : 01:11:33
try like this
UPDATE SavingsRegister
SET FK_SKSOL_ClientID=Clients.UniqueID
FROM SavingsRegister WITH(NOLOCK)
INNER JOIN Clients WITH(NOLOCK)
ON SavingsRegister.ClientID=Clients.ClientID
WHERE NOT EXISTS (SELECT * FROM tablename where RecordStatus = 'O' OR RecordStatus = 'D')
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-02-24 : 01:18:49
quote:
WHERE RecordStatus <> 'O' OR RecordStatus <> 'D'


NOTE: not OR not on the same column is ALWAYS true!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nishita_s
Yak Posting Veteran

61 Posts

Posted - 2009-02-24 : 02:03:52
Yes Webfrd, u r right. i m mistaken. there should be and not or
hi bklr RecordStatus = 'O' and RecordStatus = 'D' this condition is on the same table which i m updatting
like
UPDATE SavingsRegister
SET FK_SKSOL_ClientID=Clients.UniqueID
FROM SavingsRegister WITH(NOLOCK)
INNER JOIN Clients WITH(NOLOCK)
ON SavingsRegister.ClientID=Clients.ClientID
where recordstatus<> 'O' and Recordstatus<>'D'
so i just want to chk not in ('O','D')
n instead of not in want to use not exists
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-24 : 10:32:28
which table contains recordstatus column?
Go to Top of Page
   

- Advertisement -