how to write SQL in EXCEL VBA with intelligence prompt - sql

Please advice me how to input SQL statement in EXCEL VBA with intelligence prompt? for example, when i write select statement, system can auto prompt table field after i write a dot,just like i do it in sql server.

Related

Is there any way to create an Excel File using an Stored Procedure?

I have a table with this columns: name, surname, email, location and number with their respective data.
Is possible generate an Excel using an Stored Procedure in Azure SQL Database and store this file in my desktop with the results of my querie? Thanks!
"Is there any way to create an Excel File using an Stored Procedure?": Yes.
An SP can do anything and that you can do with T-SQL. How you create the Excel spreadsheet is up to you; SSIS, SSRS, CLR, xp_cmdshell,etc are just a few methods. You'll just need to put the appropriate query and statements in your SP, ensure you have the correct permissions and ensure the service account(s) have the appropriate permissions.
If you're asking how to create an Excel file using SQL Server, that is a completely different question.
In Azure SQL database, most of the ways to export data to an Excel file with T-SQL, such as xp_cmdshell、OPENROWSET(Managed instance only) are not suppported. Even if there's no error when creating the stored procedure, the error will happen after EXEC it.
You will get the error like:
"XXX is not supported in this version of SQL Server".
For local SQL Server, you can reference this tutorial. This tutorial provides a demo stored procedure code for you.
Azure SQL database also provides many other ways to export the data to excel files.
For example, Export SQL table to Excel using SSMS. Using the sql statements to select the data your want to the excel file.
Or you can connect to the Azrue SQL database from your new excel file, get the data you want with sql statements. Please reference the Azure tutorial: Connect Excel to a single database in Azure SQL database and create a report
Hope this helps.
enter link description here

Connection to MS access 2007 via form using vba

I have created a sample MS access 2007 database and designed a form to retrieve the records of the user , if the username and password entered in the form matches the record.In the button action it redirects to visual basic IDE . May i know how to connect to a ms access database from vba by getting the values from the form, and how to execute SQL query from that.
Learn how to work with Recordsets. To execute SQL that will not return any result use:
DoCmd.RunSQL

SSMS: query export to Excel

I am trying to export 260+ column query to Excel from SSMS 2005.
When I finish up the wizard, I get the "Too many fields defined" error.
Is there any way of getting around this?
I suppose I can run that query via New Query and copy and paste to Excel but it doesn't copy over the column names.
Thanks
This seems to be a problem of your version of Excel other than SQL Server. If you have Excel 2003 (or an older version), then you only have 256 columns, so you won't be able to "get around this". For Excel 2007+, you shouldn't have a problem at all. By the way, you can still select all records after you run your query, right-click in the results, and select "copy with headers" to get the column names.

SQL & Excel 2010

Good morning,
Does anyone know if there is an easy way I can use a SQL query in Excel to select specific data from an Excel spreadsheet without having to use VBA, Access, an SQL database or complicated Excel formula?
Thank you very much.
Use Microsoft Query.
I don't have Excel 2010 at the mo. In Excel 2007:
Ribbon: Data, From Other Sources (Get External Data From Other Sources), From Microsoft Query, Choose Data Source (dialog), Databases (tab), Excel File* (listbox), Select Workbook (dialog), browse for file, step through Query Wizard (dialog), at finish choose, View or edit query in Microsoft Query, click SQL (toolbar button) and there you can edit the query or change it entirely.
From a program you can use Jet SQL to query an Excel file.
From within Excel, I don't think you can use Jet SQL.

Is there a way to use SSIS to execute SQL statements that are stored in an Excel file?

I am using Excel to generate a whole slew of INSERT statements, similar to the process described here.
I would like to have an SSIS package that will run through each row of this excel file and run the SQL statements it finds against a database.
Is this possible?
EDIT:
As John points out - there is a better way to do it - generate the insert statement in SSIS instead of Excel. (I'm just getting my head into SSIS).
I'm sure it's possible, if a little silly. Why not generate the INSERT statements inside of SSIS?
At any rate, I suppose you'd get an Excel connection manager, use it in an Execute SQL Command task to SELECT the column with the INSERTS from Excel, and output the results to a Recordset. You'd then use a ForEach task to iterate over the recordset, putting each INSERT into a variable. Use the variable to configure an Execute SQL Task inside the ForEach task.