Solved

CAST varchar field into INT

Posted on 2007-04-03
2
923 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

737 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