SQL - Wildcard Operators


SQL Wildcard Operators are used with SQL LIKE operator, which is used to compare a value to alike values using wildcard operators.

SQL supports two wildcard operators in combination with the LIKE operator:

       ·The percent sign (%): Matches one or more characters. Note that MS   Access uses the asterisk (*) wildcard character instead of the percent sign (%) wildcard character.

  • The underscore (_): Matches one character. Note that MS Access uses a question mark (?) instead of the underscore (_) to match any one character.

Syntax:The basic syntax of '%' and '_' is as follows:

·         SELECT FROM table_name  WHERE column LIKE 'XXXX%'
·         SELECT FROM table_name WHERE column LIKE '%XXXX%'
                    AND
·         SELECT FROM table_name WHERE column LIKE 'XXXX_'
·         SELECT FROM table_name WHERE column LIKE '_XXXX'

Example: Here are number of examples showing WHERE part having different LIKE clause with '%' and '_' operators:

·         SELECT * FROM EMP_DETSILS WHERE SALARY LIKE '90%'  Select values that start with 90
·         SELECT * FROM EMP_DETSILS WHERE SALARY LIKE '%90%' Select values that have 90 in it
·         SELECT * FROM EMP_DETSILS  WHERE SALARY LIKE '_90%' Select values that have 90 in the second and third positions
·         SELECT * FROM EMP_DETSILS WHERE SALARY LIKE '_1%5'  Select values that have a 1 in the second position and end with a 5

·         SELECT * FROM EMP_DETSILS WHERE SALARY LIKE '1___5' Select  values in a five-digit number that start with 1 and end with 5

Why we can't execute a stored procedure from a User Defined function(UDF)

Functions cannot "touch" any database but read them only. Stored procedures can do anything and everything with databases. You ...