what is the use of char function

Answered what is the use of char function

  • Thursday, February 21, 2013 8:55 PM
     
     
    i am a beginner..i can't understood..can any one please explain

All Replies

  • Thursday, February 21, 2013 9:01 PM
     
     Answered Has Code

    The CHAR function returns a char for an ASCII code, for example

    SELECT CHAR(65)

    returns a "A", because 65 is the ASCII code for A ; see also CHAR (Transact-SQL)

    Olaf Helper

    Blog Xing

  • Thursday, February 21, 2013 9:02 PM
     
     Answered Has Code
    http://msdn.microsoft.com/en-us/library/ms187323.aspx
    DECLARE @i INT=65
    WHILE (@i<=99)
    BEGIN
    	PRINT CHAR(@i)
    	SET @i=@i+1
    END 


    Narsimha

  • Thursday, February 21, 2013 9:08 PM
     
     
    THEN WHAT ABOUT "Control characters" in char functions
  • Thursday, February 21, 2013 9:10 PM
     
     
    THEN WHAT ABOUT "Control characters" in char functions
  • Thursday, February 21, 2013 9:18 PM
    Moderator
     
     
    You can use CHAR(13) to insert carriage return.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

  • Thursday, February 21, 2013 9:28 PM
     
     Answered
    Or do it the other way around. Use testing against CHAR(13) and CHAR(10) to test for CR and LF. In days gone by, the stored procedure, trigger, rule and default definitions were stored in a table called syscomments. The table syscomments used to have a column called "text", I think, of the type varchar(255), and an integer column colid or something. If you read the table for the object_id of a certain proc in order of colid, and split the lines in the column text whenever you hit <CR><LF> (or CHAR(13) + CHAR(10)), and pasted the end of a line to the start of the next one, you had the text of the proc back in a readable format. These days, it is much simpler, yust read sys.sql_modules.definition for the object_id of your proc.