Click here to check my latest exciting videos on youtube
Search Mallstuffs

Flag Counter
Spirituality, Knowledge and Entertainment


Locations of visitors to this page


Latest Articles


Move to top
Different string functions in SQL-Part 1
Posted By Sarin on Mar 12, 2012     RSS Feeds     Latest Hinduism news
2319 Views

Different string functions in SQL
  
ASCII:
Return the ASCII numeric value of the leftmost character of a string


Since, Ascii value starts from 65,  Ascii value of A is 65, B is 66 and hence K is 75  

CHAR:
It’s a reverse of the ASCII function as it changes a numeric value into an ASCII character  



Can also be used to generate character for hexadecimalvalue as shown below

SELECT  CHAR(CAST(0x44 as int))  
Hexadecimal ox44 is equal to decimal value 68 and so, above query returns output as D
  

CHARINDEX
Returns the starting point of the first occurrence of one string of characters within another string
A value of 0 is returned if the string is not found.
CHARINDEX does not take into account whether the strings are upper or lower  


  

DATALENGTH ():
  returns the number of bytes used to manage a value

Since each character take 1 bytes, above string takes 7 bytes in total.


Since float variables takes 8 bytes of storage, above query returns data length as 8.
  
DIFFERENCE (): 
It’s a Wrapper around two SOUNDEX() function calls and some business logic to compare the values  between two strings. It returns the integer in a scale from 0 to 4, where the value 4 indicates a very close or exact match.


Most of the time, it returns the matched number of characters between two string as the resultant output. Mostly, used to find out string sounds similar to another string

LEFT:
Return a number of characters from the left-hand side of a string, counting characters to the right


LEN ():
 
Returns the length of a string as an integer value

  
LOWER:
Convert all characters within the string to lower case


  
LTRIM:
 
Removes leading spaces from a string or trim the white space on the left of the string

As seen above, blank spaces are removed from the beginning of the string in the output

NCHAR:
 
Returns a Unicode character representing the number passed as a parameter,
  

  
Difference between Char and nchar function is that nchar will get Unicode character for integer greater than 255 too whereas char will return null for integer greater than 255. The other diff is that nchar output will take 2 byte of storage space whereas char result will take only 1 byte of storage space

Note: Images used on this website are either a production of Bhaktivedanta Book Trust(https://www.krishna.com), Iskcon Foundation or were found in google search under "Free to use and share". If any of the images presented here violates copyright issues or infringes anyone copyright or are not under "Fair use", then please bring it to our notice. Read Disclaimer for more.

Share this to your friends. One of your friend is waiting for your share.
Related Articles
Need and advantages of using computed columns
Capitalise first character of every word
Different string functions in SQL-Part 2
Different string functions in SQL-Part 1
Did Egyptians worshipped lord krishna
Commonly used string operation in SQL
Parse comma separated input string in SQL

Post Comment