Solved

CAST varchar field into INT

Posted on 2007-04-03
2
925 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

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

Expert Comment

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

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

630 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