Use the OPENROWSET function
- Last UpdatedMar 19, 2025
- 1 minute read
The linked server name can be used as an input parameter to an OPENROWSET function. The OPENROWSET function sends the OLE DB provider a command to execute. The returned rowset can then be used as a table or view reference in a Transact-SQL statement. For example:
SELECT * FROM OPENROWSET('INSQL',' ', 'SELECT DateTime, Quality, QualityDetail, Value
FROM History
WHERE TagName in ("SysTimeSec")
AND DateTime >= "2001-09-12 12:59:00"
AND DateTime <= "2001-09-12 13:00:00"
')
Note: If the OpenRowSet/OpenDatasource component is turned off as part of the security configuration for the server, you will receive an error when you try to run this query. If necessary, a system administrator can reset SQL Server settings to enable use of ad hoc queries by executing the sp_configure command.