我正在尝试运行一个基本的select语句来返回一个作业号列表。我想接下来的工作号码列表并通过4个不同的选择语句来查看它们,看看我是否得到任何结果。这样做的目的是创建一个监视程序列表,以通知我是否尚未创建任何作业的任何部分。这是我到目前为止的代码:
--Search for all Jobs
--Use select statement here to return a list of job numbers
--Then crank through both of the following queries to see if I get any results
--Laser 1
SELECT * FROM db1.dbo.table1
WHERE PARTNAME NOT IN (SELECT PARTNAME FROM db2.Laser1.dbo.Part WHERE ORDERNO = @JobNumber)
AND DISTRICT = 1 AND ORDERNO = @JobNumber
--Laser 2
SELECT * FROM db1.dbo.table1
WHERE PARTNAME NOT IN (SELECT PARTNAME FROM db2.Laser2.dbo.Part WHERE ORDERNO = @JobNumber)
AND DISTRICT = 3 AND ORDERNO = @JobNumber
简而言之,我想使用select语句来返回当前处于进程中的所有作业。然后用该作业替换@JobNumber,看看它是否返回任何内容。
答案 0 :(得分:0)
这里的细节很稀疏,但你绝对不需要光标或循环。这样的事可能呢?
select *
from Jobs j
where j.PARTNAME not in
(
SELECT p1.PARTNAME
from db1.dbo.table1
left join db2.Laser1.dbo.Part p1 on p1.ORDERNO = @JobNumber AND DISTRICT = 1
UNION ALL
SELECT p2.PARTNAME
from db1.dbo.table1
left join db2.Laser2.dbo.Part p2 on p2.ORDERNO = @JobNumber AND DISTRICT = 3
)