I have a large table of information (around 11,000 rows, 4 columns) in Excel that uses a macro and I need to import it to an SQL server, Microsoft SQL Server Management Studio, which will be utilized by another server to get the new information.
Example:
If I type into SQL:
Insert Into ENT_LINK_OBJECTS (OBJ_NAME, ENTITY_KEY, IDENTITY_KEY)
Select 'TDS-C1487-81236', ITEM_KEY, 1
From ENT_ITEM_MASTER As M
Where M.ITEM_CODE = 'TL-123'
or M.ITEM_CODE = 'TL-456'
I can then open the program which holds all this information, called Matrix, which prompts me to enter an item key and/or code and/or type etc (which has all possible files listed below it) and hit search (image 1). If I type in TL-123 to the item code section (image 2), it narrows down the files to any containing TL-123 (image 3). When i double click, I can click on many tabs, one of which is "Links". In that tab under document name the information TDS-C1487-81236(image 4). How would I go about making that happen?
(1)
(2)
Then hit ENTER
(3)
(4)
The website below is a good explanation of what I am getting at but I do not know how to implement it. What would be the most efficient way to migrate the data from my excel document to the SQL server?
http://sqlmag.com/business-intelligence/excel-macro-creates-insert-statements-easy-data-migration
Have you tried DTSWizard ? Its a GUI based tool to do so.. and should be shipped with MS SQL server
Create a linked server or Use statement like OPENROWSET to access Excel Sheet. That would be the easiest and fastest method of accessing excel sheet via SQL.
Related
I'm doing it programmatically (I'm a newbie to sql) I'm getting the data per table within first DB using with being a value from a list of table names that I need to make sure are
there
if there have the corresponding values in the same table in
DB X list all the fields that do not have the same values and the
value in below
Table that does match listing the table, field name, row,
"SELECT * FROM [Dev.Chris21].[dbo].[" & PayrollTablemaskedarray(xxxxxx-2) & "]"
I can copy the whole thing into excel but I'm wondering is there a way to do this using sql?
Thanks
Since you mention that you're doing it programmically I assume you're using visual studio. If so you can take advantage of SQL Server Data Tools (SSDT) to do comparisons of two database schemas or two database data sets. You get this out of the box with VS2012 or VS2013 (and earlier versions too). Might be worth a look...
I want to create a VBA program where it connects to the database you give it (hard coded). From here you are to program a cell to take the input for the WHERE clause in the query and then in a separate sheet it outputs the queried data. I do not want to filter this data, I need to query it. Can anyone help?
You can do this using Microsoft Query. The basic steps are:
1 - Connect to the database using Data>From Other Sources>Microsoft Query
2 - Modify the resulting query by right-cliking the resulting table and choosing Table>External Data Properties and clicking the little icon in the upper-corner. Then choose the Definition tab:
3 - Right-click the table and choose Parameters. In that dialog you can set cells to hold the parameters for the Where clauses.
For more info on this see this MSDN page and this Daily Dose post.
I've a Microsoft Excel file with 25 columns and I used the data import wizard on SQL Server 2008 R2 studio to import it to already existing table. But, it only maps 14 columns and ignores the rest. Does it have a column number limit or there is a problem with my data?
Can you give some example of your data?
In the mean time... When you're performing your import, I assume you are reaching the Select Source Tables and Views Page;
At this stage, you can edit your column mappings by pressing the Edit Mappings button. This will show the following screen;
Make sure that all your columns are selected there.
Also, on the following screen, it will warn of any mismatches in data;
Are you seeing any warnings here?
I'm not familiar much with SQL Server, but according to this: Excel file Import to Sql server 2008 - column limit for Excel is 255 which is far beyond your numbers. Most likely problem is in your data, but without having the example it's impossible to say what's wrong.
You can do the other way around.
Step 1. Import sheet in a new table.
Step 2. Use Bulk Query to insert into your prefered table
I think this will solve your Problem.
Try to create the Excel columns and table structure in the same format and structure as ms sql table is. Open the excel select the row (whole row by clicking on row number) select the whole data till end of the data (selected first row to last row). press ctrl+c
edit the ms sql table, go to last row where you can find blank.
Select that row by clicking on row button and press ctrl+v.
Done you're excel data will be inserted into sql table.
I tried it in MS SQL 2008
I'm trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle.
I have about 10 tables, varying from 4 columns up to 25. I'm not using any constraints/keys so this should be reasonably straight forward.
Firstly I generated scripts to get the table structure, then modified them to conform to Oracle syntax standards (ie changed the nvarchar to varchar2)
Next I exported the data using SQL Servers export wizard which created a csv flat file. However my main issue is that I can't find a way to force SQL Server to double quote column names. One of my columns contains commas, so unless I can find a method for SQL server to quote column names then I will have trouble when it comes to importing this.
Also, am I going the difficult route, or is there an easier way to do this?
Thanks
EDIT: By quoting I'm refering to quoting the column values in the csv. For example I have a column which contains addresses like
101 High Street, Sometown, Some
county, PO5TC053
Without changing it to the following, it would cause issues when loading the CSV
"101 High Street, Sometown, Some
county, PO5TC053"
After looking at some options with SQLDeveloper, or to manually try to export/import, I found a utility on SQL Server management studio that gets the desired results, and is easy to use, do the following
Goto the source schema on SQL Server
Right click > Export data
Select source as current schema
Select destination as "Oracle OLE provider"
Select properties, then add the service name into the first box, then username and password, be sure to click "remember password"
Enter query to get desired results to be migrated
Enter table name, then click the "Edit" button
Alter mappings, change nvarchars to varchar2, and INTEGER to NUMBER
Run
Repeat process for remaining tables, save as jobs if you need to do this again in the future
Use the SQLDeveloper migration tools
I think quoting column names in oracle is something you should not use. It causes all sort of problems.
As Robert has said, I'd strongly advise agains quoting column names. The result is that you'd have to quote them not only when importing the data, but also whenever you want to reference that column in a SQL statement - and yes, that probably means in your program code as well. Building SQL statements becomes a total hassle!
From what you're writing, I'm not sure if you are referring to the column names or the data in these columns. (Can SQLServer really have a comma in the column name? I'd be really surprised if there was a good reason for that!) Quoting the column content should be done for any string-like columns (although I found that other characters usually work better as the need to "escape" quotes becomes another issue). If you're exporting in CSV that should be an option .. but then I'm not familiar with the export wizard.
Another idea for moving the data (depending on the scale of your project) would be to use an ETL/EAI tool. I've been playing around a bit with the Pentaho suite and their Kettle component. It offered a good range of options to move data from one place to another. It may be a bit oversized for a simple transfer, but if it's a big "migration" with the corresponding volume, it may be a good option.
I have an Access database that I use to to run a bunch of aggregate TOP 5 queries. The end game of this particular function is ppt presentations with charts. So to automate this a bit, I created an excel spreadsheet with a bunch of pre-made charts in it. The I linked/data imported the query results into the excel spreadsheet, and set the cell ranges to match the source ranges for the charts. Finally I set the spreadsheet to enable auto refresh upon every "file open", and presto, I run the queries in access with a button press, then open the excel file, and the data refreshes, and they are my charts. I then use some VB to copy paste all active charts into ppt, but that is another matter.
Okay so here is the snag I hit. I needed to do the exact same procedure with another spreadsheet from another ag query. Before the process I was using was just clicking data > import external data > import data and then choosing the file of the database, and then it would populate a list of tables and queries to choose from. Only now, it will not show any queries in that populated list; only tables!?!
any ideas? btw MSO 2003
I can't reproduce that Justin. In the dialog that shows the tables, scroll over to the right and check the TYPE column. Queries will have a type of VIEW and tables of TABLE. Verify that they all say TABLE.
Next, try using Data - Import External Data - New Database Query instead of 'Import Data'. Select the Access driver and the Access mdb. This will bring up a different dialog, but should show both tables and queries. See if that shows only tables or shows both.
I presume this is a security feature that has been introduced?
Try selecting any table then select Data>Import External Data>Edit Query
Then select SQL as the command type and either enter the query SQL or just select from a query i.e.:
select * from qryCat;
Hope this helps
thanks Mark