I have list of names of employees in a text file.
Instead of searching each name one by one, I want to search my database once for all the names of the text file. Some thing like:
select emplayeeID, Salary from employees where employee-name in "C:\myfile.txt"
Is it possible? If yes then what would be the SQL command for it? Thanks.
A query can contain both a WHERE clause and a HAVING clause. In that case: The WHERE clause is applied first to the individual rows in the tables or table-valued objects in the Diagram pane. Only the rows that meet the conditions in the WHERE clause are grouped.
The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records.
Yes, use OPENROWSET with BULK. You need a format file though.
select
E.emplayeeID, E.Salary
from
employees E
JOIN
OPENROWSET (
BULK 'c:\myfile.txt',
FORMATFILE = 'c:\myfileformat.txt'
) B ON E.name = B.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With