openrowset

pass dynamic file path of excel to “OPENROWSET”

不问归期 提交于 2019-12-02 10:51:16
I want pass dynamic URL of excel to "OPENROWSET". NOTE - I am passing returned result of excel file to cursor. I want to pass file path to "@excelpath", I have tried many ways but its giving syntax error. ALTER procedure [dbo].[import_excel] ( @excelpath as nvarchar(max) ) as begin set nocount on DECLARE insert_cursor CURSOR FOR select * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\memberdata.xlsx', [Sheet1$]) OPEN insert_cursor; FETCH NEXT FROM insert_cursor INTO @id_number, @memberName WHILE @@FETCH_STATUS = 0 BEGIN -- body of cursor FETCH NEXT FROM insert_cursor INTO

Use Parameter In OPENROWSET Sql Server

心不动则不痛 提交于 2019-12-02 05:30:25
I am creating an stored procedure in which I am calling an another stored procedure(This procedure is returned lot of columns and I want only one column value So I can't create temp table to store values) using OPENROWSET . When I am use following then it's alright declare @AgencyID int=15,@PatientID int=3701 SELECT a.PrimaryInsuredName FROM OPENROWSET('SQLNCLI', 'Server=ServerName;Database=DbName;Trusted_Connection=yes', 'exec USP_Billing_GetPatientWithInsurence 3701,15') AS a; It's working fine. But I want to pass parameters for calling USP_Billing_GetPatientWithInsurence because values will

Convert scientific notation to float when using OpenRowSet to import a .CSV file

旧巷老猫 提交于 2019-12-01 03:27:48
I am using openrowset to import a csv file into SQL Server. One of the columns in the csv file contains numbers in scientific notation (1.08E+05) and the column in the table it is being inserted By default it is importing the value as 1 and ignoring the .08E+05. I have tried using cast() and convert() to convert the value directly when the query is executed as well as setting up the datatype in the table as a character string and importing it as such. All of these methods have the same behavior where the .08E+05 is ignored. Is there a way to have the value imported as 108000 instead of 1

OPENROWSET with Excel file

限于喜欢 提交于 2019-12-01 01:30:44
I want to execute simple statement: SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Text;Database=C:\Temp\;','SELECT * FROM [test.csv]') And suddenly I get this message today morning: Msg 7308, Level 16, State 1, Line 1 OLE DB provider 'MICROSOFT.JET.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode. It was working till today morning! Here is my server specs: Windows 2008 R2 64 bit SQL Server 2008 64 bit I've installed AccessDatabaseEngine_x64.exe. Sql Server is running under LocalService account. I've set Everyone

Convert scientific notation to float when using OpenRowSet to import a .CSV file

て烟熏妆下的殇ゞ 提交于 2019-12-01 00:17:16
问题 I am using openrowset to import a csv file into SQL Server. One of the columns in the csv file contains numbers in scientific notation (1.08E+05) and the column in the table it is being inserted By default it is importing the value as 1 and ignoring the .08E+05. I have tried using cast() and convert() to convert the value directly when the query is executed as well as setting up the datatype in the table as a character string and importing it as such. All of these methods have the same

SQL Server: Cannot initialize the data source object of OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)”

烂漫一生 提交于 2019-11-30 14:54:36
问题 I am trying to run the following query: SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Somefile.xlsx', 'SELECT * FROM [Sheet$]') But I get this error: Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". I tried the following: sp_configure 'show advanced options', 1; RECONFIGURE; sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE; GO And: USE [master] GO EXEC master . dbo. sp_MSset_oledb_prop N

SQL Server: Cannot initialize the data source object of OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)”

折月煮酒 提交于 2019-11-30 12:12:51
I am trying to run the following query: SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Somefile.xlsx', 'SELECT * FROM [Sheet$]') But I get this error: Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". I tried the following: sp_configure 'show advanced options', 1; RECONFIGURE; sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE; GO And: USE [master] GO EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1 GO EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft

'Microsoft.ACE.OLEDB.12.0' 64x Sql Server and 86x Office?

做~自己de王妃 提交于 2019-11-29 15:17:55
问题 The error: OLE DB provider 'Microsoft.ACE.OLEDB.12.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode. And the answers I'm seeing is a conflict between 64 bit Sql Server and 32 bit Office. Is there a way to run an openrowset on Excel into Sql Server? insert into dbo.FiscalCalendar select * from openrowset('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;Database=C:\Users\uname\Desktop\fy11.xlsx;', 'Select * from [Sheet1]') 回答1: ..

T-SQL: issue with string concat

不打扰是莪最后的温柔 提交于 2019-11-29 13:18:26
I have a set of audio files with names GreenLine1.mp3, GreenLine2.mp3 e.t.c. I'm going to write them into a table as BLOB (I use MS SQL Server'08), here's my sql request: DECLARE @aud AS VARBINARY(MAX) DECLARE @num AS INT -- Load the audio data SET @num=1 WHILE (@num<38) BEGIN; SELECT @aud = CAST(bulkcolumn AS VARBINARY(MAX)) FROM OPENROWSET( BULK 'C:\Users\Ilya\folder\GreenLine' + CAST(@num AS VARCHAR) + '.mp3', SINGLE_BLOB ) AS x -- Insert the data to the table INSERT INTO Mb2.dbo.Audios (Id, [Content]) SELECT NEWID(), @aud SET @num = @num + 1 END; I have an error: Incorrect syntax near '+',

error executing OPENROWSET (BULK) / Azure SQL Database

北城以北 提交于 2019-11-29 12:35:32
I am logged into an Azure SQL Database, using "Active Directory - Integrated" authentication wherein I supply my company domain credentials only; no password. I tried executing OPENROWSET on a .json file stored on my client (laptop): Select BulkColumn from OPENROWSET (BULK 'C:\Users\username\Downloads\docs_by_day_IncludeDocs.json', SINGLE_CLOB) as my_test which returned: Msg 4861, Level 16, State 1, Line 12 Cannot bulk load because the file "C:\Users\username\Downloads \docs_by_day_IncludeDocs.json" could not be opened. Operating system error code (null). Does this error have something to do