Answers for "not in sql server"

SQL
0

if not exists in sql

At first glance your original attempt seems pretty close. I'm assuming that clockDate is a DateTime fields so try this:

IF (NOT EXISTS(SELECT * FROM Clock WHERE cast(clockDate as date) = '08/10/2012') 
    AND userName = 'test') 
BEGIN 
    INSERT INTO Clock(clockDate, userName, breakOut) 
    VALUES(GetDate(), 'test', GetDate()) 
END 
ELSE 
BEGIN 
    UPDATE Clock 
    SET breakOut = GetDate()
    WHERE Cast(clockDate AS Date) = '08/10/2012' AND userName = 'test'
END 
Note that getdate gives you the current date. If you are trying to compare to a date (without the time) you need to cast or the time element will cause the compare to fail.

If clockDate is NOT datetime field (just date), then the SQL engine will do it for you - no need to cast on a set/insert statement.

IF (NOT EXISTS(SELECT * FROM Clock WHERE clockDate = '08/10/2012') 
    AND userName = 'test') 
BEGIN 
    INSERT INTO Clock(clockDate, userName, breakOut) 
    VALUES(GetDate(), 'test', GetDate()) 
END 
ELSE 
BEGIN 
    UPDATE Clock 
    SET breakOut = GetDate()
    WHERE clockDate = '08/10/2012' AND userName = 'test'
END 
As others have pointed out, the merge statement is another way to tackle this same logic. However, in some cases, especially with large data sets, the merge statement can be prohibitively slow, causing a lot of tran log activity. So knowing how to logic it out as shown above is still a valid technique.
Posted by: Guest on March-12-2021
1

not operator in sql

(NOT) operator excluding given
For example:
Select last_name, job_id From Employees
Where "Not" job_id = 'ABC';
Posted by: Guest on January-27-2021
0

sql not

Returns true if a record DOESN’T meet the condition.
Example: Returns true if the user’s first_name doesn’t end with ‘son’.
SELECT * FROM users
WHERE first_name NOT LIKE '%son';
Posted by: Guest on January-07-2021
3

sql not in

SQL NOT IN operator is used to filter the result if the values that are mentioned as part of the IN operator is not satisfied. Let’s discuss in detail about SQL NOT IN operator.

Syntax:
SELECT Column(s) FROM table_name WHERE Column NOT IN (value1, value2... valueN);
Posted by: Guest on April-22-2020
0

not in sql

(NOT) operator excluding given
For example:
Select last_name, job_id From Employees
Where "Not" job_id = 'ABC';
Posted by: Guest on January-28-2021
0

is not in sql server

select * from TableName(nolock) where onlineUser!=('Y')
Posted by: Guest on January-29-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language