TRACEYMARY
asked on
SQL Not exists
I have
SELECT UDT02_ID, UDT09_ID
FROM DELTEKTC.DELTEKET.ET_LINK2 9
WHERE UDT02_ID IS NOT NULL
AND UDT09_ID IS NOT NULL
and UDT02_ID LIKE '00401016.0004' + '%'
I then want to check that it does not exists in table below i tried the following
WHERE NOT EXISTS ( SELECT UDT09_ID, UDT02_ID FROM PCAPP.dbo.PCARD_TCL)
but errors
Incorrect syntax near the keyword 'WHERE'.
SELECT UDT02_ID, UDT09_ID
FROM DELTEKTC.DELTEKET.ET_LINK2
WHERE UDT02_ID IS NOT NULL
AND UDT09_ID IS NOT NULL
and UDT02_ID LIKE '00401016.0004' + '%'
I then want to check that it does not exists in table below i tried the following
WHERE NOT EXISTS ( SELECT UDT09_ID, UDT02_ID FROM PCAPP.dbo.PCARD_TCL)
but errors
Incorrect syntax near the keyword 'WHERE'.
SELECT UDT02_ID, UDT09_ID
FROM DELTEKTC.DELTEKET.ET_LINK2 9
WHERE UDT02_ID IS NOT NULL
AND UDT09_ID IS NOT NULL
and UDT02_ID LIKE '00401016.0004' + '%'
and NOT EXISTS ( SELECT UDT09_ID, UDT02_ID FROM PCAPP.dbo.PCARD_TCL)
FROM DELTEKTC.DELTEKET.ET_LINK2
WHERE UDT02_ID IS NOT NULL
AND UDT09_ID IS NOT NULL
and UDT02_ID LIKE '00401016.0004' + '%'
and NOT EXISTS ( SELECT UDT09_ID, UDT02_ID FROM PCAPP.dbo.PCARD_TCL)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Whats the select 1 for ?
SELECT '1' --will return 1 if the criteria matches, you can return any value, *, or any column name
ASKER
Thanks ......i appreciate it
ASKER
Is there a better way to write this
Write to temp table then
loop around temp
IF NOT exists (select x, y from table)
Insert
loop again
I understand it more when its long winded lol
Write to temp table then
loop around temp
IF NOT exists (select x, y from table)
Insert
loop again
I understand it more when its long winded lol
>Is there a better way to write this
This is the optimized code,
This is the optimized code,
SELECT UDT02_ID, UDT09_ID
FROM DELTEKTC.DELTEKET.ET_LINK2
WHERE UDT02_ID IS NOT NULL
AND UDT09_ID IS NOT NULL
and UDT02_ID LIKE '00401016.0004' + '%'
AND NOT EXISTS ( SELECT 1 FROM PCAPP.dbo.PCARD_TCL)
Cheers!