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

Changing VarChar to Number

Status
Not open for further replies.

Crystalguru

Technical User
Oct 4, 2001
303
US
Hello,

I need to convert a VARCHAR(255) field to a number field, either decimal or int, doesn't matter.

I have tried using the cast and convert but keep getting an error message that is cannot change the field. Here's the formula I am using.

CAST((CONVERT(VARCHAR(10), pnd.text)) AS INT)as weight

Not sure why it is not working?

Thanks
 
Yes, you are correct, some of the columns do not contain numeric data.

With a where statement like this
where pnd.typecode = weight. There is only number values.

So, I tweaked my statement to the following:
CAST((CONVERT(VARCHAR(8), pnd.text)) AS decimal)as weight

And it works!

Wala.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top