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

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.

Related

Best way to duplicate data in the same table and updating a column at the same time

I'm trying to find the best way to duplicate all the rows in a table.By this i mean inserting them again in the same table, but i need to update a single column only on the values that were inserted.
This is to help me write a script so I can automate some work on some clients.
I can't use select * as it will throw an error because of the identity columns but at the same time i don't want to be manually writting all the column names for several tables.
Is there a simple way to translate this into SQL server?
Sorry for not showing a piece of code, but i have nothing at the moment and i'm not really fluent in SQL.
EDIT: I have ended up following the advice of JamieD77 in the comments below this post by moving everything to a table, drop the id column, updating what i need and then moving back as it seems to be the most effiecient.
In SQL Server Management Studio you can drag the "Columns" folder under a table and drop it on the query window and it will paste a comma-delimited list of all the columns.
Or run a query like:
select string_agg(quotename(name),', ')
from sys.columns
where object_id = object_id('MyTable')

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.

find column name in sql query

I would like to use the GUI to find q column name in my sql query which has more than 300 columns
For example: I want to use GUI provided by SQL to find all the column names starting with VENDOR and hi-light them in order to make my operation easier..
I just want to use GUI
P.S: No query suggestions please, I am already aware of them (using like and all)
In MSQL Studio, use the Query Designer (Design Query In Editor...), paste your SQL, then use the name column in criteria pane to copy and paste in excel

Need list of columns (fields) in a SQlite table within Visual Basic

I'm building a query application in VS 2012 in which the user drills down by sequentially selecting the Database, then Table, then Column for the search. Database and Table selection work fine. Column selection not-so-much.
Table selection is the following SQL query Command String:
Dim ThisSQLcs As String = "SELECT `name` FROM sqlite_master WHERE type = 'table';"
Similar syntax for getting Column data does not work (type = "column") because there are no column/field types in sqlite_master. I have seen suggestions in other posts that work from the CLI (.schema tablename) or something about PROGMA table_info('table_name'), but neither of those work in this VS / VB context.
Any suggestions would be appreciated.
-larry

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

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.