• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

T-SQL : Variables

Hi !

There's a part of the code from a report a run everyday that I can't understand.

	DECLARE @CRLD CHAR(2) = CHAR(13) + CHAR(10)
	DECLARE @LineBreak VARCHAR(10) = @CRLD + '<br />'

Open in new window


Can someone explain me the prupose of this.

Thank You !

-M
0
Rubicon2009
Asked:
Rubicon2009
4 Solutions
 
Adam MenkesC# ASP.NET DeveloperCommented:
It appears you are storing a variable @CRLD as 2 characters, a carriage return and a line feed.
The 2nd variable @LineBreak adds the first variable plus an HTML break for output to the web.
0
 
tlovieCommented:
What it does is declare a @CRLD as a CHAR(2), and assigns the ascii values chr(13) and chr(10) to it (CR + LF)
then it does the same for @LineBreak, it defines it as a varchar(10) and assigns the value of @CRLD concatenated with '<br />'

0
 
Rubicon2009Author Commented:
Butt how is it possible to store 23 characters in a 2 characters space ?
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
derekkrommCommented:
char(13) and char(10) are 1 character each

char(13) represents a carriage return
char(10) represents a line feed

for example, do "select char(70)" in query analyzer and you'll get "F", a single character. 70 is the ascii representation of "F"
0
 
Adam MenkesC# ASP.NET DeveloperCommented:
It is not 23 characters. CHAR(2) is defining the storage type of 2 characters.

CHAR(13) is the ASCII code for a Carriage return, it is not 13 characters.
CHAR(10) is the ASCII code for Line Feed, not 10 characters.
0
 
deightonCommented:
CHAR(2) means 'two character variable', but then very confusingly CHAR(13) + CHAR(10) means concatenate ASCII character 13 to ASCII character 10

CHAR has different meaning on each side
0
 
Rubicon2009Author Commented:
Thank you ! I'm very surprised, I was not expecting this kind of logic at all.
0
 
Rubicon2009Author Commented:
Thank a lot !
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now