Solved

CAST varchar field into INT

Posted on 2007-04-03
2
916 Views
Last Modified: 2008-02-01
I need to CAST a varchar field (Product Number)  that has product numbers that always start with a "BP_some number" into an INT for just the numeric part. For example, if I have the product number BP_4361, I need to CAST this so that I have 4361 as a resulting INT.
Hope this makes sense.
Best regards,
W Delaney
0
Comment
Question by:wdelaney05
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
select cast ( substring ( product_number , 4, 20 ) as int )
from yourtable
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
SELECT SUBSTRING('ColumnName', CHARINDEX('_','ColumnName')+1,LEN('ColumnName'))
FROM urTable
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Truncate vs Delete 63 87
Grid querry results 41 51
Selection from table2 where criteria for table1 10 19
Sql query 34 16
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now