Vba sql statements in Excel

The SQL stands for Structured Query Language.

SQL is a standard language for sorting, manipulating and retrieving data from a database.

SQL is also a standard language for Relational Database System(RDBMS).

The SQL Statements are used to perform various operation on database.

The various SQL statements are as discussed below:

SELECT Statement

The SELECT Statement is used to retrieve a set data from a database.

There are various forms of SELECT statement which are as discussed below:

SELECT * FROM

The above statement retrieves all the records from a table in a database.

SELECT FROM

The above statement retrieves the first column alone from the mentioned table.

SELECT , FROM WHERE

The above statement explains various things.

The Select statement can be used to retrieve more than one column and which satisfies a specified condition.

UPDATE Statement

This statement is used to Update a database table.

The following syntax shows this:

UPDATE SET = WHERE

The above statement is self explanatory, where a column value is updated based on certain conditions being satisfied.

DELETE Statement

The DELETE Statement is used to delete existing records from a table.

DELETE FROM WHERE

The above statement deletes a record from a table based on a condition.

LIKE Operator

The LIKE operator is used in a WHERE Clause to search for a specified pattern, if not, the exact match.

The following systax explains this:

SELECT FROM WHERE LIKE

INSERT INTO

This statement is used to add new record in a table.

The following syntax explains this:

There are two types of INSERT Statement.

1.INSERT INTO (,) VALUES (,)

2.INSERT INTO VALUES (,)

As seen from the above rwo syntax, the first one is used with column names and the latter is without column names.

ORDER BY

The ORDER BY is used to sort the resulting data in a recordset.

The Syntax for ORDER BY is as shown below:

SELECT , FROM ORDER BY , ASC|DESC

By default, the ORDER BY keyword sorts data in ascending order.

AND,OR,NOT

The SQL supports logical statements as any other programming language, but it can only be used in WHERE Clause.

These operators are useful while retrieving data based on multiple conditions.

SELECT , FROM WHERE OR AND

There are various other statements and operations which are available SQL that can be accessed in VBA.

 

You can find similar Excel Questions and Answer hereunder

1) I have to make an investment decision - I have the cashflow numbers. In Excel, how do I calculate Internal Rate of Return (IRR)?

2) Here an explanation about label controls in the various forms and controls using VBA

3) I am using Excel for Project Management - how can I find End Date for a task given Start Date and Task duration considering only working days?

4) What is a recordset in Excel and how to use it. Here are some basic explanations

5) Generate a list of unique values in Excel

6) How can I generate random numbers between 2 limits?

7) How to add a link in a sheet to another sheet

8) I am considering an investment of $500 per month for 3 years @ 6% interest rate. What is the Present Value of investment?

9) Here some explanations about xml and how to use xml in VBA

10) Here some explanations about the XML DOM node in VBA, DOM stands for Document Object Model

 

Here the previous and next chapter