Log in  ::  Register  ::  Not logged in

## how to you make this 44.8730084 into this: 44.8%

 Author Message 99posts SSC Veteran Group: General Forum Members Points: 299 Visits: 22 use a select statement; how do you make this44.8730084into this44.8 %actually doesn't even have to be a percent ( % ) could simplybe a truncate of sorts to appear like this 44.8any help, or direction on this would be great.many thanks Ray K SSChampion Group: General Forum Members Points: 13713 Visits: 4959 Go to BOL and look up numeric data types . . . +--------------------------------------------------------------------------------------+‌Check out my blog at https://pianorayk.wordpress.com/ Ray K SSChampion Group: General Forum Members Points: 13713 Visits: 4959 99posts (12/28/2009)use a select statement; how do you make this44.8730084into this44.8 %BTW, 44.873 would round to 44.9, not 44.8 (this is the math guy in me coming out here) . . . +--------------------------------------------------------------------------------------+‌Check out my blog at https://pianorayk.wordpress.com/ Bru Medishetty SSChampion Group: General Forum Members Points: 13200 Visits: 1950 Ray is right. You would be getting 44.9 rather than 44.8Start with this.`select ROUND(44.8730084,1) -- gives 44.9000000 as output` Or try this way.`declare @val float;set @val = 44.8730084select ROUND(@val,1,1) -- gives 44.8 as outputselect ROUND(@val,1,0) -- gives 44.9 as output` Bru MedishettyBlog -- LearnSQLWithBruJoin on Facebook Page Facebook.com\LearnSQLWithBru Twitter -- BruMedishetty 99posts SSC Veteran Group: General Forum Members Points: 299 Visits: 22 thanks for the replies... the value i gave was just a sample not the actual results coming out of the query.and it wouldn't be just 'that' value; would be applied to any value returned fromthe 'percent' column.i'm not that great with tsql, but from the looks of it the examples apply to justone value and not the range queried ( forgive me if i misunderstand )any how; what about truncating the 52.2027837 to something like this52.2any ideas?thanks in advance ravi_m_s Valued Member Group: General Forum Members Points: 69 Visits: 24 select substring(cast(44.8730084 as varchar),1,4)+'%' Ray K SSChampion Group: General Forum Members Points: 13713 Visits: 4959 Did you read BOL like I suggested? (Not trying to dance around the answer -- just trying to encourage you to look it up and figure it out on your own before asking questions, which is highly encouraged in this forum.)There are a number of data types that will do this for you. For example, try DECIMAL.Try messing with the numbers (including the 4 and 1 in the decimal declaration) in this example in your SQL and see what it does for you . . .`declare @number decimal(4,1)select @number = 10.2436select @number` +--------------------------------------------------------------------------------------+‌Check out my blog at https://pianorayk.wordpress.com/ GilaMonster SSC Guru Group: General Forum Members Points: 549803 Visits: 47744 ravi_m_s (12/28/2009)select substring(cast(44.8730084 as varchar),1,4)+'%'Why would you want to convert to a varchar just to round a number off? String conversions are expensive operations. Gail ShawMicrosoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)SQL In The Wild: Discussions on DB performance with occasional diversions into recoverabilityWe walk in the dark places no others will enterWe stand on the bridge and no one may pass 99posts SSC Veteran Group: General Forum Members Points: 299 Visits: 22 is ok... is a very small db.let me see what i can do with these examples.thanks to all! Ray K SSChampion Group: General Forum Members Points: 13713 Visits: 4959 If you're trying to convert from a table, try playing with this example:`declare @temp table(thisval float)insert into @temp values (23.61)insert into @temp values (1234.13456143)insert into @temp values (100.00001)insert into @temp values (12.34)insert into @temp values (3.14159)insert into @temp values (10.01)select cast(thisval as decimal(6,2)) from @temp`Note: if I'm not mistaken (and someone correct me if I'm wrong), it's generally not advisable to put a function into a SELECT statement, since it can use processor time. +--------------------------------------------------------------------------------------+‌Check out my blog at https://pianorayk.wordpress.com/

## Permissions

 You can't post new topics. You can't post topic replies. You can't post new polls. You can't post replies to polls. You can't edit your own topics. You can't delete your own topics. You can't edit other topics. You can't delete other topics. You can't edit your own posts. You can't edit other posts. You can't delete your own posts. You can't delete other posts. You can't post events. You can't edit your own events. You can't edit other events. You can't delete your own events. You can't delete other events. You can't send private messages. You can't send emails. You can read topics. You can't vote in polls. You can't upload attachments. You can download attachments. You can't post HTML code. You can't edit HTML code. You can't post IFCode. You can't post JavaScript. You can post emoticons. You can't post or upload images.

##### Select a forum
 SQL Server 2017      SQL Server 2017 - Administration      SQL Server 2017 - Development SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 15 - Administration      SQL Server 15 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions      CosmosDB      Azure Data Lake      Azure Machine Learning Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization      Security and Auditing SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      SQL Server Security Skills      Question of the Day (QOD) Microsoft Access      Microsoft Access Products and Books      Third Party Products         SQLCentric         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         Golden Gate Software         Idera         Lumigent         Red Gate Software         ApexSQL         Quest Software         CA      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 2000 Books         Discuss SQL Server 7.0 Books Notification Services      Administration Article Discussions Future Versions      SQL 12

## Search

 Copyright © 2002-2018 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.