Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CAST varchar field into INT

Posted on 2007-04-03
2
Medium Priority
?
928 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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

721 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