Tuesday, 1 September 2015

Difference Between PatIndex and CharIndex


The CHARINDEX and PATINDEX functions return the starting position of a pattern you specify. PATINDEX can use wildcard characters, but CHARINDEX cannot.

These functions take two parameters:
·     The pattern whose position you want. With PATINDEX, the pattern is a literal string that can contain wildcard characters. With CHARINDEX, the pattern is a literal string without wildcard characters.

·         A string-valued expression, generally a column name, searched for the specified pattern.

SELECT CHARINDEX('JA','VIJAY')

O/P :- 3

SELECT PATINDEX('%GMAIL%','VIJAYK0286@GMAIL.COM')

O/P :- 12

SELECT PATINDEX('%GM__L%','VIJAYK0286@GMAIL.COM')

O/P :- 12







Difference Between Where and Having

WHERE
HAVING
WHERE CLAUSE WILL BE USED TO FILTER THE DATA BEFORE THE GROUP BY CLAUSE.
HAVING CLAUSE WILL BE USED TO FILTER THE DATA AFTER THE GROUP BY CLAUSE.
WHERE CLAUSE WILL BE APPLIED ON DATA DIRECTLY.
HAVING CLAUSE WILL BE APPLIED ON AGGREGATED DATA i.e. SUM, MAX, MIN,..
APART FROM SELECT STATEMENT WE CAN USE THIS WHERE CLAUSE WITH UPDATE, DELETE.
APART FROM SELECT STATEMENT WE CAN NOT USE THIS WITH ANY COMMAND.