Solved

T-SQL : Variables

Posted on 2011-03-04
8
396 Views
Last Modified: 2012-05-11
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
Comment
Question by:Rubicon2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 19

Expert Comment

by:Adam Menkes
ID: 35036499
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
 
LVL 7

Accepted Solution

by:
tlovie earned 125 total points
ID: 35036521
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
 

Author Comment

by:Rubicon2009
ID: 35036523
Butt how is it possible to store 23 characters in a 2 characters space ?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 15

Assisted Solution

by:derekkromm
derekkromm earned 125 total points
ID: 35036532
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
 
LVL 19

Assisted Solution

by:Adam Menkes
Adam Menkes earned 125 total points
ID: 35036534
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
 
LVL 18

Assisted Solution

by:deighton
deighton earned 125 total points
ID: 35036611
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
 

Author Comment

by:Rubicon2009
ID: 35036618
Thank you ! I'm very surprised, I was not expecting this kind of logic at all.
0
 

Author Closing Comment

by:Rubicon2009
ID: 35036642
Thank a lot !
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CAST issue with SQL 2000 15 42
Sql Query 29 30
mssql 7 32
Creating Scalar Function 3 15
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question