Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Databases Programming Interviews:BtrieveClipperData ModelingData StructuresDatabase AdministrationDatabase Administrator (DBA)Database AnalystDatabase DeveloperDB DevelopmentEDI/Data Integration ExpertFirebirdHierarchicalIBM DB2InformixJava DatabaseMariaDBMicrosoft Access DeveloperMongoDBMS SQL ServerMySQL ProgrammingNetworkNoSQLObject RelationalPostgrePostgreSQLProgressRDBMSRelationalSQLSQL AdministratorSQL and PL/SQLSQL Notification ServicesSQL server 2008SSRSStored ProcedureSybaseTeradata
Copyright © 2018. All Rights Reserved
MS SQL Server Interview Question:
How To How To Convert Numeric Expression Data Types using the CONVERT() Function??
Submitted by: AdministratorIf you want to convert the data type of a numeric expression to a new data type, you can use the CONVERT(data_type, expression) function. The tutorial exercise below shows you how to use the CONVERT() function:
-- FLOAT converted to NUMERIC by CONVERT()
DECLARE @pi FLOAT(24);
SET @pi = 3.141592E+00;
SELECT CONVERT(NUMERIC(5,2), @pi);
GO
3.14
-- FLOAT converted to NUMERIC by CONVERT()
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CONVERT(NUMERIC(10,5), @x);
GO
12345.12012
-- FLOAT converted to INT by CONVERT()
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CONVERT(INT, @x);
GO
12345
Submitted by: Administrator
-- FLOAT converted to NUMERIC by CONVERT()
DECLARE @pi FLOAT(24);
SET @pi = 3.141592E+00;
SELECT CONVERT(NUMERIC(5,2), @pi);
GO
3.14
-- FLOAT converted to NUMERIC by CONVERT()
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CONVERT(NUMERIC(10,5), @x);
GO
12345.12012
-- FLOAT converted to INT by CONVERT()
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CONVERT(INT, @x);
GO
12345
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.