The correct syntax is not in
:
SELECT name, modify_date
FROM sys.objects
where col = value and datecol >= datevalue and
col not in ('Value1', 'Value2', 'Value3')
order by xxxx;
Pergunta
We have two database servers, db1 and db2, unlinked. I cannot link them.
I have a query that goes something like:
SELECT name, modify_date
FROM sys.objects
where col = value and datecol >= datevalue and
not exists(select ObjectName
from table2
where ObjectName = sys.objects.name and
DateTime > sys.objects.modify_date and
ObjectType = Type
)
order by xxxx
Originally that would work just fine because we were looking at DB1 for changes. Now that I'm modifying the program to look at the two database servers for new objects created, the table on DB1 does not exist on DB2, and I need to find a way to rewrite the query in some way that will allow me to retrieve the info from the table on DB1, and then use it in a comparison on db2.
I've been trying to something like
SELECT name, modify_date
FROM sys.objects
where col = value and datecol >= datevalue and
not exists('Value1', 'Value2', 'Value3')
order by xxxx
So that I can just return the sub query, build a string, and drop it back in. However, the syntax to do the SQL portion is eluding me. I would prefer to stay away from "col <> 'value1' and col <> 'value2' and col <> 'value3'.
Does anyone have any suggestions?
Using SQL Server 2008 and modifying an old vb6 application that is not ready for a rewrite into .net yet..
Solução
The correct syntax is not in
:
SELECT name, modify_date
FROM sys.objects
where col = value and datecol >= datevalue and
col not in ('Value1', 'Value2', 'Value3')
order by xxxx;