SQl to Excel keeps formatting to E+03 - sql

so I keep trying to export sql columns with values that have 8005E1 and it keeps showing up excel as '8005E+03'
is there a way i can prevent that? do i need to add a function to my sql query or something?
I tried editing the format to text but then it converts my string from '8005E1' to '8005' is which I don't want
any ideas?

Related

Excel multiline cell import in SQL Server via ADODB

I have a field in Excel with comments. People enter data with line breaks in a cell (ALT + ENTER).
Is there a way via Excel VBA to import this via ADODB to SQL Server 2016, so I can also retrieve it again as multiline from the database?
An example: in Excel I have a multiline cell with value:
TEST
TEST
TEST
When I retrieve it again via the database it will show TESTTESTTEST, I would like to show the same as in Excel.
I tried both
rs![comment] = cell value
and
t-sql (simplified): insert into comment_table (comment) VALUES cell value
In both cases when I retrieve the data, I only get one string like in the example.
Hope somebody has an idea to solve this.
Already found the solution.
Field has to be of type nvarchar. If I query the table in SQL Server, I only see one string.
TESTESTTEST
If I for example retrieve it in Excel in a pivot and set the field to wrap text, it will apply the line breaks again.

Best Method to Query SQL using Variable Excel Values

There's an SQL database that I would like to query through excel without having to pull the entire SQL database into excel (5Million + rows). I have established the connection in excel. The values that I will be using to query the SQL Database are variable (typically around 150-200 cells).
End Result: The variable cells in excel are all in column A, I would like to query the Column A SQL values to retrieve the Column B SQL value and pull them back into excel. I know I could download the whole SQL database into excel and do a vlookup but my excel file will undoubtedly crash with all the SQL data.
Does anyone know where I should start? Would this best be resolved through VBA code or the advanced editor directly in excel?
Cheers,
Brandon M
You can include "?" in the query text of your connection. The first time you run the query, Excel will ask you what each of the "?" references. You can then change the values in those cells, and refresh the connection to use those new values.
Your situation is a bit unclear to me.
Do you want to perform "Select * from table where column in (Cell A)"? and then to print into Cell B?
If yes, you can use VBA code to build your SQL query and select the data.
If you don't want to use VBA, you can use some cell concatenation to build the query and can pass the query to SQL.

SQL Convert from alphanumeric to numeric only

Ok, I have a table I am querying for an outside project. The table has a field that is alphanumeric but the external project can only support numeric data. The outside project is needing my data as an Excel spreadsheet so I am trying to just export my query to Excel which I can do but I can't seem to figure out if there is a simple convert feature to do this for me. The originating table has the field as VARCHAR(10). I tried CAST and CONVERT but no go. This is SQL Server 2012.
Thanks.

INT Inserted in SQL as NULL SSIS Package Excel to SQL

I have setup an SSIS package to take data from an excel file, and insert it into SQL.
The package takes the data from Excel, performs some Data Conversions, and then Inserts it into my SQL DB.
One of the columns in excel contains both text, and ints. Typically the values will be either: W2 or 1099.
In the data conversion data flow, this column is converted to: string[DT_STR], length: 50, Code Page: 1252 (ANSI - Latin I)
in SQL, the field it is going to is configured as a varchar(50).
For any row, where the column value in Excel is 1099, the data inserted into SQL, comes through as NULL.
I have no idea what could be causing this. I have similar conversions in other packages, that come through with no issues.
i have tried formatting the column in excel as text as well as re-creating the data conversion, with no luck.
Any suggestions of ways to get this to work properly appreciated. Please let me know if you need any additional information.
Is the data NULL in the Excel preview? You need to isolate whether this NULL is being provided by the Excel driver.
Anyway this sounds like the old IMEX=1 issue that has been around since forever.
http://microsoft-ssis.blogspot.com.au/2011/06/mixed-data-types-in-excel-column.html
Try adding IMEX=1 to your Excel connection string.

Easier Way to Format Excel Data For SQL query

I often receive requests to query a SQL Server database based on data that is sent to me in an Excel spreadsheet.
I am looking for a more efficient way of completing these types of requests than my current setup:
Currently in order to complete the request I do the following:
Copy the Excel column containing the data that will eventually be placed in a WHERE clause.
Paste the data as text only into Microsoft Word.
Do a find for each paragraph marker and replace it with ', '
Then surround the entire clause with parenthesis to enter into an IN clause.
Does anyone have a suggestion for a more efficient way of accomplishing the same task?
Here are a couple of ways:
Query the excel spreadsheet directly:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\excelfile.xls', [Sheet1$])
Use excel to format the data:
In next empty column = A1 & "," then copy-down, or ="'"&A1&"',"
You could save the excell as a CSV comma delimited file and go from there but if this is a regular thing i would probably set up an SSIS process to do it all for you