|
INTERVIEW QUESTIONS
DATABASE
MS SQL SERVER
DETAILS
Question: How To Convert Numeric Expression Data Types by Assignment Operations?
Answer: An assignment operation is used to assign an expression to a variable, a column, or a parameter. If the data type of the expression does not match the data type of the receiving variable, column, or parameter, SQL Server will perform an implicit data type conversion on the expression. Note that implicit data type conversion during assignment operation can convert a higher rank data type to a lower rank data type, which may resulting in losing data during the conversion. The tutorial exercise shows you some good examples: -- INT converted to NUMERIC DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @i = 123; SET @d = @i; SELECT @d; GO 123.000 -- INT converted to NUMERIC DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @i = 123; SET @d = @i; SELECT @d; GO 123.000 DECLARE @pi FLOAT(24); DECLARE @dp NUMERIC(5,2); SET @pi = 3.1415927E+00; SET @dp = @pi; SELECT @dp; GO 3.14
|
|
|
Category |
MS SQL Server Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8392 users |
Added on |
9/23/2014 |
Views |
67327 |
Rate it! |
|
|
Question:
How To Convert Numeric Expression Data Types by Assignment Operations?
Answer:
An assignment operation is used to assign an expression to a variable, a column, or a parameter. If the data type of the expression does not match the data type of the receiving variable, column, or parameter, SQL Server will perform an implicit data type conversion on the expression. Note that implicit data type conversion during assignment operation can convert a higher rank data type to a lower rank data type, which may resulting in losing data during the conversion. The tutorial exercise shows you some good examples: -- INT converted to NUMERIC DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @i = 123; SET @d = @i; SELECT @d; GO 123.000 -- INT converted to NUMERIC DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @i = 123; SET @d = @i; SELECT @d; GO 123.000 DECLARE @pi FLOAT(24); DECLARE @dp NUMERIC(5,2); SET @pi = 3.1415927E+00; SET @dp = @pi; SELECT @dp; GO 3.14 Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How To Convert a Numeric Expression from One Data Type to Another?
|
View Answer
|
|
What Is an Expression in MS SQL Server?
|
View Answer
|
|
What Are the Underflow and Overflow Behaviors on FLOAT Literals?
|
View Answer
|
|
How REAL and FLOAT Literal Values Are Rounded?
|
View Answer
|
|
How Extra Digits Are Handled with NUMERIC Data Type Literals?
|
View Answer
|
|
What Happens If an Integer Is Too Big for INT Date Type?
|
View Answer
|
|
What Are Out-of-Range Errors with Date and Time Literals?
|
View Answer
|
|
What Happens If Time-Only Values Are Provided as Date and Time Literals?
|
View Answer
|
|
What Happens If Date-Only Values Are Provided as Date and Time Literals?
|
View Answer
|
|
Why I Can Not Enter 0.001 Second in Date and Time Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Date and Time Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Binary String Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Unicode Character String Literals in MS SQL Server?
|
View Answer
|
|
How Fixed Length Strings Are Truncated and Padded?
|
View Answer
|
|
How To Find Out What Is the Default Collation in a Database?
|
View Answer
|
|
What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server?
|
View Answer
|
|
How To Specify the Collation for a Character Data Type in MS SQL Server?
|
View Answer
|
|
What Is a Collation in MS SQL Server?
|
View Answer
|
|
How To Write Character String Constants or Literals in MS SQL Server?
|
View Answer
|
|
What Is a Constant or Literal in MS SQL Server?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All MS SQL Server Interview Questions & Answers - Exam Mode /
Learning Mode
|