Clear, practical technology insights About · Contact

LITERAL in SQL Server: What You Need to Know

Understand LITERAL in SQL Server with clear explanations, practical examples, and useful tips. This updated guide covers the essential concepts and common...

Published: 3 minutes read
Table of Contents

LITERAL in SQL Server is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

The article will guide you in detail how to use Literal - Hang (strings, integers, decimals, and datetime values) in SQL Server.

Literal Description (Hang)

In SQL Server, Literal relates to fixed values that the program cannot change. Literal can be any type of value, specifically divided into string constant values, integer constants, real constants, and time constant values.

String Literals - Hang String

Sequence of strings is always in single quotes.

 'quantrimang.com' 
 'ABC' 
 '123' 

The example above contains separate strings within each pair of single quotes. However, there is a case in the string that also contains an apostrophe. For instance,:

 'quantrimang.com is very great! It's my favorite site! ' 

In this example, the string contains an apostrophe in the word It. This single quotation mark makes the break statement in the second parenthesis as follows:

 'quantrimang.com is very great! It ' 

To resolve this error to avoid subsequent commands, you need to add a similar single quotation mark to escape from it:

 'quantrimang.com is very great! It''s my favorite site! ' 

Integer Literals - Constant integer

Integer constants include negative integers and positive integers, not including decimals. If you don't specify a specific marker, the program will default to your constant as positive. Representing valid integer constants is as follows:

 2018 
 +2018 
 -2018 

Decimals Literals - Real Constant

The real constant includes negative integers, positive integers and even decimal numbers. If you don't specify a specific marker, the program will default to your constant as positive. Representing valid real constants is as follows:

 2018,11 
 +2018,11 
 -2018,11 

Datetime Literals - Hang Value time

Frequently Asked Questions

What should you know about literal Description (Hang)?

In SQL Server, Literal relates to fixed values that the program cannot change. Literal can be any type of value, specifically divided into string constant values, integer constants, real constants, and time constant values.

What should you know about string Literals - Hang String?

Sequence of strings is always in single quotes.

What should you know about integer Literals - Constant integer?

Integer constants include negative integers and positive integers, not including decimals. If you don't specify a specific marker, the program will default to your constant as positive. Representing valid integer constants is as follows:

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.