Want to use Excel2010 cell column as driver for SQL Server 2008 query - sql

Tough to believe I'm the only one but..I want to use the Connection functionality in Excel to connect to a SQL Server database and populate column X based upon using a value in Excel column A as the primary key, but unable to find out how.
I have tried (typing in the command text window)
select name
from pbaTable
where
pbaid = (and this is where I'm stuck)

Took me a while to find this too!
step 1:
Put a question mark into the command text
select name
from pbaTable
where
pbaid = ?
step 2:
When you refresh the query you will be prompted for the value enter a number - enter something.
step 3:
Now go back to the command string in connection properties (ie. connections / properties / definition) - The parameters button should now be enabled - press it
step 4:
select the parameter on the left and the "get the value from the following cell" radio button on the right.
step 4:
Type in the coordinates of the cell that contains the id eg. =summary!$J$1

You'd have to import values from Excel col A that you want to participate in your join with SQL Server table pbaTable col pbaid or, the other way around, import data from SQL Server table pbaTable into Excel.
Before you can join or limit data in a where clause, you need the data on the same source, or connected in some virtual manner.

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.

Excel - Off Page Reference to Microsoft Query

I am utilizing Microsoft Query in Excel to tap into an ERP table structure like Crystal would do.
In writing the SQL, is there a way to have a filter pulled from the active Excel worksheet that is embedded in the SQL instead of prompting and editing the query?
My main problem is a Like [Prompt]% in the Excel GUI for the users to change like order numbers.
Is it possible to do an off page reference from MS Query to Excel?
If by "Microsoft Query", you're talking about the window that looks like it was coded for Windows 95, stop using it. This is provided for retro-compatibility.
Anyway, if you've displayed the criteria bar in MS query, you can type a name between brackets e.g. [Something] and MS query will prompt you to fill a value.
Not what you want yet but getting close. When you return to Excel and refresh the query, the prompt will now offer you the possibility to use a cell instead of a value you need to type every type.
In the more modern connection utility accessible via menu data > Connections (+ available even if you created your table via MS Query btw), you can achieve that by using question marks in the WHERE clause.
For instance, instead of SomeField = 'SomeValue', write SomeField = ?
Then, click on the Parameters button and you'll see all the parameters you've set, each of them can be attached to a cell's value.

Dynamic SQL Server query in Powerapps

I have created a simple form in Powerapps which has a text input field called name and a data table which shows a list of all customers from a table called customer in a SQL Server database and I have also added a button labelled "Go" on the form.
What I want to do is:
See a blank data table when I first open the form
I would enter a customer name in the name text input field
Click the "Go" button and then the value from the name field will be passed to the SQL Server database in a query which only returns
the records which have the same name
Display the results of the query in the data table.
How can I do this?
Thanks
Assuming you've been able to correctly add your on-premise SQL server as a data source:
You'll want to use a combination of Collect() and Filter()
Assign your user input to a variable using (this isn't strictly necessary)
GetContext({UserVariable: TextInput.Text})
Use a combination of Collect() to store the data you pull from MSSQL, and Filter() to, well, filter the data.
Collect(AppStorageTable1, Filter('[dbo].SqlTable]', ColumnName1 = UserVariable))
If you assign AppStorageTable1 as your data source for your data table, it should now appear. (Note, you'll have to declare/create it before it will appear as an option, but once you've used the name in Collect() it will appear as a data source).
EDIT: The term you likely were looking for is "delegable", a quick search will yield a few articles about it. The "Filter" function will pass the work off to your SQL server, so your app won't be responsible for processing/filtering the data.

Access Query by form that runs SQL Server view as a backend query

I have a Access DB with SQL Server as Backend DB, all the tables in Access are linked from SQL Server. I want to create a query by form for keyword search. I am planning to have a access form such as:
Step 1: Shows a dropdown that lists all the tables in the DB, once a table is selected
Step 2: another dorpdown shows up that lists all the column names in the selected table, once a column is selected
Step 3: then a text box appears where I enter a keyword that will run a select query on the selected table with the criteria on the selected column that is entered in the text box and gives the result.
Now I have a SQL Server query to list the column names of a given table.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = 'table-name')
ORDER BY ORDINAL_POSITION
I want to use this query for the second step.
I cannot understand how to connect Access QBF to run a query in SQL Server.
Should I make a view or stored procedure in SQL Server?
Can someone please tell me how to get this done.
Thank You.
There is an easy way to do this using MS Access.
If you set the row source of table select combo to:
SELECT [name] FROM msysobjects WHERE type=4;
Then add a little code:
Private Sub cboTable_AfterUpdate()
Me.cboFields.RowSource = Me.cboTable
End Sub
And set the field selection combo Row Source Type to Fields, you should get what you want.
You can link views from SQL Server to MS Access.

Is there a web site where I can paste a SQL Insert statement and have it break it out by column?

I've been working on an application that has no discernable data access layer, so all the SQL statements are just built up as strings and executed. I'm constantly confronted by very long INSERT statements where I'm trying to figure out what value in the VALUES list matches up with what column in the column name list.
I was about to create a little helper application where I could paste in an INSERT statement and have it show me a list of values matched up with the column names, just for debugging, and I thought, "someone else has probably done this already."
Does anyone know of a web site where I can just paste in an INSERT statement and have it show me a two column table with column names in the first column and values in the second column?
not a website but have you tried either visual studio or Sql Server Management studio. Both of these are able to do this.
You can use SQL Server Management studio or Visual Studio (with Server Explorer) to do that. For SSMS, follow these steps:
On a random table, click "Edit Top 200 Rows"
Open the SQL pane and paste your Insert script.
Open the Criteria Pane, which displays the insert column value pairs.
http://www.dpriver.com/pp/sqlformat.htm
I use Red Gate SQL Prompt for all my re-formatting.
Even though it is unnecessary (and unused), I often use aliases to make it easier to line things up, so instead of:
INSERT INTO tbl
SELECT 2 * y
FROM other_tbl
I usually do:
INSERT INTO tbl (x)
SELECT 2 * y AS x
FROM other_tbl