![]() ![]() ![]() In addition I'll add a pattern search, but this solution returns all records that matches the pattern: LIKE 'emp%' If you need the TOP (X) rows WHERE employee_id LIKE 'emp1%' plus TOP (X) rows WHERE employee_id LIKE 'emp3%' you can use two select statements joined with UNION ALL. Keep in mind that you're using TOP 1, you'll get one row maximum, no matter how many conditions you use. I've set up an example: create table employees(employee_id varchar(10), employee_name varchar(100)) Have a look at OR (Transact-SQL) on MS-Docs. ON employee.ident = employee_mdata_history.employee_ident You should use an OR/AND condition: SELECT TOP (1) INNER JOIN dbo.employee_mdata_history AS h You can always use short aliases to avoid repeating potentially long table names. That makes your query easier to read/understand. to every pattern, limiting the number of rows for each pattern to the corresponding value from the pattern list.Īs a side note, please let me take this opportunity to suggest that you always qualify your columns with the table alias in a query that is reading from two or more tables. The CROSS APPLY operator applies your query to every row of the pattern list, i.e. The VALUES row constructor represents your pattern list as a table, additionally supplying each pattern with the number of rows to retrieve for that pattern. ON employee.ident=employee_mdata_history.employee_ident Alternatively you can try the following method: SELECTĮmployee_id, employee_ident, utc_dt, rx_dt ![]()
0 Comments
Leave a Reply. |