openrowset

Import EXCEL data to SQL Server without data conversion

℡╲_俬逩灬. 提交于 2020-01-24 01:31:06
问题 I am trying to insert excel data into sql server tables. Each column should be imported with the exact same format that the user wrote in the source Excel. I am using following query to fetch data SELECT * FROM OPENROWSET( 'Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;IMEX=1;Database=H:\Loadloandata\Test\K3.xlsx', 'SELECT * FROM [Sheet1$]') But now in the date column of excel we are receiving some float values( format issues from the users) as shown below Because of the invalid data,

SQL JOIN on varchar with special characters and leading zeros

半城伤御伤魂 提交于 2020-01-15 10:38:08
问题 I have a problem with join on varchar column. I'm going to update SQL data from Excel data by product code but Twr_Kod is varchar and it is the only way to join with Excel data. There is also problem with convert to varchar when there are leading zeros. select CDN.Towary.Twr_Kod, excel.Twr_Kod from CDN.Towary left join openrowset('Microsoft.ACE.OLEDB.12.0', Excel 8.0;Database=C:\excel\towary.xlsx;', 'select * from [Arkusz1$]') excel on cast(CDN.Towary.Twr_Kod as varchar) = cast(excel.Twr_Kod

Upload csv Files Using SQL Server OpenRowSet Function

百般思念 提交于 2020-01-13 06:48:37
问题 I need to upload multiple files (file1, file2, file3...) into tables (Table1, table2, table3...) in a sql server DB using OpenRowset function. All the files are kept in C:\download I use the following query which works fine. INSERT INTO dbo.Table1 SELECT * from OpenRowset('MSDASQL','Driver={Microsoft Text Driver (*.txt;*.csv)};DefaultDir=C:\download;','select * from File1.csv' ) The question is how to pass the file name and table name as parameter. Thanks Tony for your answer. I have put the

Connect to a webservice from SQL

随声附和 提交于 2020-01-12 07:50:09
问题 SQL Server is able to open excel sheets (xlsx), access databases (mdb) and other data streams using data providers (e.g. JET, ACE) and OPENROWSET. Are there similar facilities to extract data from a remote webservice ? Using OPENROWSET and providing it a web service driver and URL and some schema definition to translate the hierarchical nature of the webservice XML output into a table that SQL Server can query on. I'm thinking of something like: select * from OPENROWSET('WEBSERVICE.4.0

Call sqlcmd commands in stored procedure code

时光怂恿深爱的人放手 提交于 2020-01-06 03:21:46
问题 Because of Linked Server is not easy to send openrowset query I connect to remote Sql Server directly via SQLCMD mode. But this is Ok using Query Analyzer. When I put code to stored procedure I cannot even save it: :Connect x.x.x.x -U sa -P password select * from openrowset('VFPOLEDB','\\share\db\s_object.dbf';''; '','SELECT * FROM s_object where i_class=21 order by 1') Incorrect syntax near ':'. 回答1: sqlcmd mode :connect syntax is valid in SSMS and QA when sqlcmd mode is enabled, but it will

openrowset - How to select from a filename with white spaces?

早过忘川 提交于 2020-01-04 07:09:23
问题 This is working : SELECT * FROM OPENROWSET('MSDASQL','Driver={Microsoft Access Text Driver (*.txt, *.csv)}; Extended Properties="text; HDR=YES; FMT=Delimited"','SELECT * FROM E:\folder\subfolder\myfile.txt') This is not working because of the white spaces: SELECT * FROM OPENROWSET('MSDASQL','Driver={Microsoft Access Text Driver (*.txt, *.csv)}; Extended Properties="text; HDR=YES; FMT=Delimited"','SELECT * FROM E:\folder\sub folder\my file.txt') I tried with doubles quotes ("...") and with [..

I have a problem inserting more than 255 chars per column into an Excel file using INSERT INTO OPENROWSET from SQL Server

*爱你&永不变心* 提交于 2019-12-25 02:22:34
问题 I am getting an error while exporting data from SQL Server to an already created .xlsx file using openrowset . It works fine most of times, but when the data comes in of the field as a large string, while inserting into Excel, it shows this error: The statement has been terminated, string or binary data would be truncated. Data gets inserted into table, but while inserting in Excel, this error appears. Please help me find a solution. 回答1: As the error mentions "data would be truncated", you

Error while running node-mssql query

依然范特西╮ 提交于 2019-12-24 01:18:13
问题 I am trying to run node-mssql query, if I run simple quires it is getting executed. But when I use OPENROWSET and Microsoft.ACE.OLEDB.12.0 , it is showing some errors. Here is server.js code var express = require('express'); var app = express(); app.get('/', function (req, res) { var sql = require("mssql"); // config for your database var config = { user: '..', password: '....', server: 'localhost\\SQLEXPRESS', database: 'test_databasae' }; // connect to your database sql.connect(config,

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

时间秒杀一切 提交于 2019-12-24 00:58:08
问题 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 #mytemptable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database="+@file+";HDR=YES', 'SELECT * FROM [Sheet1$]')" EXEC (@SQL) That much seems to work. However, if I then try something like this: Select * from #mytemptable I get an error:

XML parsing error: why is semicolon expected? [duplicate]

冷暖自知 提交于 2019-12-23 17:22:11
问题 This question already has answers here : What are invalid characters in XML (15 answers) Closed 3 years ago . I'm a newbie struggling with trying to import XML from an external third-party into SQL Server. I tried this SQL with the XML below and it pukes with "XML parsing: line 10, character 81, semicolon expected" in the middle of the Name tag - WHY?? Why would it expect a semicolon in the middle of a value? Any suggestions?? Thanks in advance! CREATE TABLE XMLD (Id INT IDENTITY PRIMARY KEY,