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.
Related
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?
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.
Using in Excel: Get Data>Other sources>Microsoft Query I had a table getting data from our company ERP system (ODBC).
I have a table in Excel and then I click in Excel: Data>Queries&Connections>Properies>Connection Properties>Definition and in "Command text" i put this simple SQL command:
SELECT F4111.ILLITM, F4111.ILTRQT/1000, F4111.ILTRUM, F4111.ILDGL, F4111.ILGLPT, F4111.ILDCT, F4111.ILUNCS, F4111.ILPAID, F4111.ILDOC, F4111.ILMCU
FROM RBGDC0P2.UREEUPBD.F4111 F4111
WHERE (F4111.ILLITM IN ('XXXXXXX', 'YYYYYYY')) AND (F4111.ILDCT LIKE '%AA%')
XXXXXXX and YYYYYYY are my input codes, which I need some data for them. 'F4111' is a table, ILLITM is my column from ERP database.
I can put ? to open a parameter and connect in to particular cell in Excel, and then I can simply change this cell in excel and refresh a table a have output for different input codes.
My question is: I want to have more parameters, like I put in excel column with 100 input codes and I need output for them by refreshing my table query. I can do it for one or few inputs by putting '?', but how can I do it for more?
I have an SQL query that returns several things, including the date and time that an email was sent, as well as the body of that email. However, when I copy and paste the data to Excel, the body of the email does not stay in one cell, but takes up several cells, many times spanning several rows.
I have not used text-to-columns recently.
Does anyone know how to remedy this?
Thanks!
If you import data from 'Data' -> 'New Query' -> 'From Database' -> 'From Sql Server database' -> Provide your server name, database name and sql query to import data into excel, will get single attribute values to single column in excel
I'm trying to get SQL Server 2012 data into Excel 2013.
You can see my sample command text. If I write date parameter manually, like this:
set #dt = getdate()
it works well. But I need to pass it the Excel cell value, for example A1 value as shown in the picture. Is it possible? If yes, how?
Please note: I do NOT want to use vba macro connection, need to pass it via this form only.
Jeroen's answer applies to SQL Queries also, but it's not obvious how to implement them, since Excel doesn't appear to expose the option in advance, and the 'parameter' button is grayed out.
Write the query with question marks in place of the value to be used in the query:
SELECT * FROM dbo.TABLE AS T where t.Date = ?
Upon saving the query, a prompt appears that lets you select a cell or range to use as the value in place of the question mark.