How to create SQL Server import template - sql

For example I have daily Excel (xlsx) file, which I need to import every day in MS SQL Server Express 2014 which is located in localhost. Firstly Truncate the table.
How can I create some template to import Excel file into MS SQL server?
For example it will be in folder: C:\Reports\1.xlsx
For truncate I know the query:
USE [CompDB];
GO
TRUNCATE TABLE [dbo].[Report_table];
GO
I tried to find in MSSQL Import - Export wizard some templates option, haven't found it there. Moreover, I tried to do this with Toad for SQL Server, but there are no templates available in free version.
Or maybe you know how to do this with MySQL database? It will be better choice for me.

Try the OLEDB approach
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 8.0;HDR=NO;Database=C:\Data\Data.xlsx','SELECT * FROM [SheetName$]')
The parameters can vary depending on your Excel version, but I think this will work for you

Related

How do I import an Excel spreadsheet into SQL Server 2008R2 database?

I have got huge list of contact information in an Excel sheet that I would like to turn into table in the database so that I can maintain them in the database.
I tried following the import/export flat file import from the SQL Server 2008 R2, but it did not work. Can anyone tell me how do I successfully import the spreadsheet into a table in the database?
Thanks
There is a microsoft knowledge base article that lays out all the ways this is possible.
http://support.microsoft.com/kb/321686
I think using OPENROWSET or OPENDATASOURCE will be the easiest way, without the wizard. (see Distributed Queries)
SELECT * INTO XLImport4 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [Customers$])
See OPENROWSET documentation, with examples lower down the page.
http://msdn.microsoft.com/en-us/library/ms190312.aspx
Manually
Right click on the database name/go to task and then select import data, as a source select an excel file that you created before and choose it's path on the next page select sql server as destination

Syntax for writing to a SQL Server table from SPSS

I just had an ODBC connection created between a SQL Server database and SPSS. I see a lot of threads about importing data FROM SQL Server into SPSS, but I am looking for syntax for writing TO the SQL Server database from SPSS.
Can anyone provide an example of an insert or update statement do to this? Thank you!
You can generate example syntax by using the wizard at File > Export to Database. Or look at SAVE TRANSLATE /TYPE=ODBC.
This is way kludgy, but you might be able to do this by installing pypyodbc, an odbc library for python, and then creating the records from within python.
The trick is to download pypyodbc and then deposit the file in SPSS python library folder (mine is C:\Program Files\IBM\SPSS\Statistics\22\Python\Lib). From there, you can import pypyodbc and execute sql statements from within a syntax file.

How to import CSV to SQL Server 2005 w/o BCP?

I am working on a ColdFusion (feel free to laugh) 8 site that that is hosted in a shared environment. The database and the web server are separate boxes. We don't have root access to either, and we don't have "exec xp_cmdshell" permission. SQL Server version is 2005.
So, what is the closest equivalent to BULK INSERT that we should try if we would like to efficiently import a CSV or other text file into the database--but without BCP or "format files"?
Obviously, we could just build a massive INSERT statement in ColdFusion, with UNION ALLs for each row, and run that. But is that the best option? Your thoughts?

Microsoft SQL Server: How to export data from a database and import them to another database?

How can I export all of my rows in a table to sql script in Microsoft SQL Server 2005 and then import them to another database?
Thanks in advance
If you moving it to another sql db you can right click the database you want and choose tasks -> generate scripts. That will launch a a wizard - follow along, choose the option to script all tables and data. Then execute that script in the new db(assuming that you've already created one with the same name)
If you can't find a data import/export tool that will work in your particular circumstances, it's possible to write plain SQL SELECT queries that will generate SQL INSERT statements. In this way it's possible to "export" all your data to a script file that can be run against the destination database. It's kind of an ugly hack, but it's simple and it works if you don't have a lot of data to move. See my answer to this question for details: Export SQL Server 2005 query result to SQL INSERT statement?
Note that this method assumes that the destination table already exists. But it's pretty straightforward to generate table creation scripts, as J Cory's answer has already shown.
There's a command line tool available to dump your data from particular tables into a SQL script that be executed against a different database:
http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/
I don't believe SQL Management Studio Express supports data scripting (as your screenshot on J Cory's answer shows), but the full version does support that feature. In either case, the command line tool should accomplish what you need.

Importing ODBC database to MS SQL 2005

How do I get a database from ODBC data source to SQL Server 2005? Can I use SQL Managment Studio Express for this?
Yes. Right-click on your database and go to Tasks: Import Data.
It used to be called DTS, but every SQL Server 2005/2008 comes with something called SSIS that is used to import and export data. You can import data into a database from any source, including flat text file, or .xls spreadsheet.