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
The above statement retrieves the first column alone from the mentioned table.
SELECT
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
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
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
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
2.INSERT INTO
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
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
There are various other statements and operations which are available SQL that can be accessed in VBA.