Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with formatting a response to 2 decimal places pls

Status
Not open for further replies.

eiluj68

Programmer
Joined
Mar 22, 2010
Messages
1
Location
GB
I'm new to MS SQL and am having trouble formatting a result to 2 decimal places. Hoping someone here could help please?

The current syntax is,

(cast(substring(Narrative,patindex('%BENCHMARK-%',Narrative) + 10,patindex('%/TAKEN-%',Narrative) - (patindex('%BENCHMARK-%',Narrative) + 10)) as decimal(17,2)) - cast(substring(Narrative,patindex('%TAKEN-%',Narrative) + 6,patindex('%/CXR-%',Narrative) - (patindex('%TAKEN-%',Narrative) + 6)) as decimal(17,2))) / cast(substring(Narrative,patindex('%BENCHMARK-%',Narrative) + 10,patindex('%/TAKEN-%',Narrative) - (patindex('%BENCHMARK-%',Narrative) + 10)) as decimal(17,2)) * '100' as SavingsPercent

The result comes out to 6 decimal places but I need it to just 2.

If you can help I'd be very grateful. Many thanks.
 
Have you tried the ROUND function? Try out the following code.

DECLARE @SomeNumber FLOAT
SELECT @SomeNumber = 123.4567891

SELECT ROUND(@SomeNumber, 2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top