displaying only 2 decimal places in a string field t-sql

maqskywalker
maqskywalker used Ask the Experts™
on
i'm using sql server 2016.

I have a table that looks like this:

p1.PNG
The data looks like this:

p2.PNG

Here is script to create table:

USE [TestDatabase]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestScores1](
	[RecordID] [int] NULL,
	[Score] [varchar](50) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[TestScores1] ([RecordID], [Score]) VALUES (1, N'100.00000')
GO
INSERT [dbo].[TestScores1] ([RecordID], [Score]) VALUES (2, N'94.00001')
GO
INSERT [dbo].[TestScores1] ([RecordID], [Score]) VALUES (3, N'86.12345')
GO
INSERT [dbo].[TestScores1] ([RecordID], [Score]) VALUES (4, N'76.05365')
GO
INSERT [dbo].[TestScores1] ([RecordID], [Score]) VALUES (5, N'88.04563')
GO

Open in new window


How do i only display 2 decimal places in the [Score] column ?

I know that column should be decimal datatype.
But the existing table is varchar. I'm just querying an old table that was created like that.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
Cast as decimal?
select recordid, cast(score as decimal(10,2)) score from testscores1;

Open in new window

Author

Commented:
thanks
Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:
btw, you should never use a varchar field to store decimal values

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial