Questions tagged [openrowset]

OPENROWSET is a T-SQL function that can be used in Microsoft SQL Server to read remote data from an OLE DB data source. It also supports bulk operations that can read data from a file and return it as a rowset.

OPENROWSET is a T-SQL (Transact-SQL) function that can be used to read remote data from many sources, for example an OLE DB data source or a file from the file system.

This method is an alternative to accessing tables in a linked server and is a one-time, ad hoc method of connecting and accessing remote data by using OLE DB. For more frequent references to OLE DB data sources, use linked servers instead.

OPENROWSET also supports bulk operations through a built-in BULK provider that enables data from a file to be read and returned as a rowset.

The OPENROWSET function can be referenced in the FROM clause of a query as if it were a table name. The OPENROWSET function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query might return multiple result sets, OPENROWSET returns only the first one.

354 questions
4
votes
2 answers

SQL SELECT * FROM OPENROWSET with Variable

I am trying to pass a variable into a SELECT statement in OPENROWSET but I keep getting an error DECLARE @dDateTIME DATE SET @dDateTIME = (SELECT SalesDate FROM dbo.SalesDate) INSERT INTO dbo.tblSales SELECT * FROM OPENROWSET('MSDASQL',…
user2393602
  • 51
  • 1
  • 1
  • 3
4
votes
1 answer

How to use OpenRowSet to insert data into a blank file?

How to use OpenRowSet to insert data into a blank file? I need to insert into a txt file (say to D:\TDB) some select output (say select * from sys.tables) from the database INSERT INTO…
serhio
  • 28,010
  • 62
  • 221
  • 374
4
votes
1 answer

reading in variables from a csv file in a SQL procedure

I have hundreds of .xlsx files that I would like to import into a database table. I have the names of the files in a csv file. I would like to loop through that csv file to make the import process of these hundreds of files more simple. Here is…
Geoff Dawdy
  • 886
  • 6
  • 15
  • 42
3
votes
4 answers

OPENROWSET - how to read everything as text?

I am using the following command to load data into SQL Server: INSERT INTO [NewTable] SELECT * FROM OPENROWSET ( 'MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\SomeFolder\;' , 'SELECT * from [SomeFile.csv]' ); The problem is…
Karl
  • 5,573
  • 8
  • 50
  • 73
3
votes
1 answer

Open Blob fields using Openrowset in SQLSERVER 2008 R2

I need help to read a fileobject from SQLServer2008 R2 using the Openrowset, i can write a File to a Blob column like this: INSERT INTO myTable(FileName, FileType, Document) SELECT 'Text1.txt' AS FileName, '.txt' AS FileType, *…
user741233
3
votes
1 answer

Pass file by @parameter to OPENROWSET BULK json query, SQL 2016

In sql 2016 This works: SELECT @JSONFileData = BulkColumn FROM OPENROWSET (BULK 'C:\Temp\Students_2015.json', SINGLE_CLOB) as JSON This does not: SELECT @JSONFileData = BulkColumn FROM OPENROWSET (BULK ' + @FullFile + ' , SINGLE_CLOB) as…
3
votes
1 answer

How do I use a path stored in table with OPENROWSET?

I have just recently began using OPENROWSET to insert images into a table. Previously, I would specify the path to each image (1 image = 1 INSERT statement), and use PHP to generate the image's binary string: INSERT INTO nopCommerce..Picture…
Derek Foulk
  • 1,892
  • 1
  • 19
  • 37
3
votes
1 answer

BCP utility to create a format file, to import Excel data to SQL Server 2008 for BULK insertion

Am trying to import Excel 2003 data into SQL table for SQL Server 2008. Tried to add a linked server but have met with little success. Now am trying to check if there's a way to use the BCP utility to do a BULK insert or BULK operation with…
Loser Coder
  • 2,338
  • 8
  • 42
  • 66
3
votes
2 answers

t-sql, sql table inner join spreadsheet

I have a table (AmenityData) of data and a column of this table contains postalsectors e.g. E14 7 I also have an Excel spreadsheet with a list of postal districts e.g. E14 I need to get all the data out of the AmenityData table where the postal…
Jammer
  • 2,330
  • 11
  • 48
  • 77
3
votes
1 answer

Openrowset function failure

I'm executing this openrowset function: SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Users\JCPABALAN\Desktop\Data Migration\ListOfDiscards.xlsx;HDR=YES', 'SELECT * FROM [Sheet1$]') But it gave me the…
user3709209
  • 61
  • 2
  • 10
3
votes
3 answers

SQL SERVER bulk insert ignore deformed lines

I have to import SAP unconvered lists. These reports look quite ugly and are not that well suited for automated processing. However there is no other option. The data is borderd around minus and pipe symbols similar to the following…
Toby
  • 570
  • 2
  • 8
  • 23
2
votes
1 answer

How to refer to files relative to project root in deployment of a database project?

I have a database project in Visual Studio 2010 where in the post-deploy script I want to import the binary data from two files into the database. To that end, I have code very much like the following in a file referenced from the post-deploy script…
user
  • 6,897
  • 8
  • 43
  • 79
2
votes
3 answers

Using openrowset to read an Excel file into a temp table; how do I reference that table?

I'm trying to write a stored procedure that will read an Excel file into a temp table, then massage some of the data in that table, then insert selected rows from that table into a permanent table. So, it starts like this: SET @SQL = "select * into…
mattstuehler
  • 9,040
  • 18
  • 78
  • 108
2
votes
1 answer

Not all rows are imported using OPENROWSET in SQL Server

I have a problem whit an import from a TXT file to a Table in SQL Server 2016, that fails import all rows. I'm trying to read the data using OPENROWSET statement, whit an XML to define the correct format of the columns in the file. So I use this…
2
votes
0 answers

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered

I am trying to import an Excel file into SQL Server for that I decided to use OPENROWSET. I have done below steps: Step 1:- sp_configure 'show advanced options', 1; RECONFIGURE; GO sp_configure 'Ad Hoc Distributed Queries',…
Sree
  • 101
  • 3
  • 10
1 2
3
23 24