SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to convert a varchar to decimal number with 7
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

563 Posts

Posted - 12/30/2012 :  10:22:30  Show Profile  Reply with Quote
How to convert a varchar number to decimal with max length 7.

select emp_no from employee;

emp_no is available in varchar format, now want to convert to decimal.
example of empnos can be: 320, 7880, 123890, 3425678

Thanks a lot for the helpful info.

Flowing Fount of Yak Knowledge

7174 Posts

Posted - 12/30/2012 :  10:34:34  Show Profile  Reply with Quote
Why Decimal?? Can't you convert to int?
Go to Top of Page

Aged Yak Warrior

535 Posts

Posted - 12/31/2012 :  11:52:49  Show Profile  Reply with Quote

If you're sure the value is numeric, you can CAST it to the desired data type:

CAST(column_name AS decimal(7, 0))
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/01/2013 :  23:56:17  Show Profile  Reply with Quote
decimal with scale value of 0 is as good as integer

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000