How to implement following query
I have a table called for example SomeTable
with columns ID
Line开发者_如何转开发
Machine
Slot
.
Is it possible to make following query and how ?
I have a List of IDs to get as result table with results if values from my list located in the table.
If it in the table get some positive result if not some negative result.
Thanks for help.
In SQL Server
, you need to declare a table variable and fill it with your ids:
DECLARE @myids TABLE (id INT NOT NULL PRIMARY KEY)
INSERT
INTO @myids
VALUES (1)
INSERT
INTO @myids
VALUES (2)
…
SELECT CASE s.id WHEN t.id THEN 1 ELSE 0 END
FROM @myids t
LEFT JOIN
sometable s
ON s.id = t.id
In both systems, you could use inline sets:
SELECT CASE s.id WHEN t.id THEN 1 ELSE 0 END
FROM (
SELECT 1 AS id
UNION ALL
SELECT 2 AS id
UNION ALL
…
) t
LEFT JOIN
sometable s
ON s.id = t.id
strike that (my) answer.
When you say "path in" do you mean "pass in" or point to a file in the external file system?
精彩评论