Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with QUOTENAME and ASCII Common String functions in SQL server 2008.

Author: Shehzad Hemani

In this simple article you will learn that how to work with different common String functions in SQL Server using PL/SQL.

ASCII ()

ASCII () is one of the most commonly used string functions in SQL Server. It is used to find the ASCII value for the leftmost character of the given string.
 
It takes only one parameter; ‘character’, which can be of type char or varchar or any character.
 
 
Syntax:
ASCII (character_expression)
 
Example:
SELECT ASCII('N')
 
Output:
-------------
78
 
If any string is given to find the ASCII value, it can be done using the other function and computing ASCII value for each character one by one. Or for any specific character, ASCII value can be find out by given its position.
 
To find the ASCII value for a specific character from a given string, which is ‘e’ here:
 
Example:
DECLARE @string char(11)
SET @string = 'some string'
SELECT ASCII(SUBSTRING(@string, 4, 1))
 
Output:
-------------
101
 
 
To find the ASCII value for the whole given string:
 
Example:
DECLARE @string char(11), @pos int;
SET @string = 'some string';
SET @pos = 1;
WHILE @pos <= LEN(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @pos, 1))
SET @pos = @pos +1;
END
 
Output will be the ASCII value of one character in every iteration.
 
 
 QUOTENAME  ()
QUOTNAME () is one of the most commonly used string functions in SQL Server. It is used to find the Unicode string with the delimiters to make a string valid Microsoft SQL delimited identifier.
 
It takes two parameters; first is the Unicode character string and second parameter is the quote character used to quote the Unicode string.  The second parameter is optional. If it is not given, default quote characters are ‘[ ]’.
 
 
Syntax:
QUOTENAME (character_expression, quote_character)
 
Example:
SELECT QUOTENAME('test() function')
 
Output:
-------------
[test() function]
 
To find the quote string with a specified quote character.
 
Example:
SELECT QUOTENAME('test() function', '}')
 
Output:
-------------
{test() function}
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with RAND FLOOR LOG LOG10 EXP functions in SQL server 2008.

Disclaimer - Privacy
© 2002-2017 DevASP.net