Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Aged Yak Warrior

567 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

550 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  
 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.04 seconds. Powered By: Snitz Forums 2000