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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I convert text to integer?

Status
Not open for further replies.

john0532

Programmer
Jul 2, 2002
27
0
0
US
I'm new to Transact-SQL. I've got a number in a varchar field that I need to get the numeric value of. How do I go about this?

Thanks
 
It's always best to give an example of some data, but here goes:


SELECT CONVERT(int, datafield)

Replace datafield with whatever your varchar datafield name is. This will ONLY work if there are numbers and only numbers in the field.

-SQLBill
 
Great. Now how do I put the numerical value into a variable of type int?
 
Just like I showed you.

Let's say this is your VARCHAR column with numeric data:

COL
1
534652
7381704
721
793948
9866

What I gave you will take that data and return it as an integer.

If that's NOT what you wanted, please explain it futher and provide sample data and what you want done with it.

-SQLBill
 
Thanks again. Your statement "returns it as an integer" answered my question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top