Query syntax convert?

Dear expert

Sometime I hate myself for the convert sql query that I still need help with it! Goddamnit... ok never mind...
Here is the question: I need to get query in a column with int value: 2131212-2312 and I wanna select only 2131212 ignore -2312.
I know there needs to be a convert because I tried with only 2131212 result was none.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WeTiAuthor Commented:
And I found a way tho, just do: WHERE db.number LIKE '2131212%'; but anyway I still need to learn convert, so i give the point to someone who give me the convert query. thanks.
What do you want to convert? Do you want to convert string to int?
In this case try this code

Open in new window

If you want convert int to string use this code:
SELECT CONVERT(varchar(10), number) FROM Table

Open in new window

ste5anSenior DeveloperCommented:
The problem is: You have a string, not a number. Thus you need to cut the number part you want to convert. This depends on the used SQL dialect and also on further constraints of your domain.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

WeTiAuthor Commented:
As I said the column has numbers like: 2131344-23444, I want to ignore what ever behind the -
ste5anSenior DeveloperCommented:
This depends on the used SQL dialect and also on further constraints of your domain.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SharathData EngineerCommented:
try like this.
create table test1(col varchar(100))
insert into test1 values ('2131212-2312')
select convert(int, substring(col, 1, charindex('-',col)-1)) 
  from test1
-- 	2131212

Open in new window

WeTiAuthor Commented:
I want to close this question now, Sharath you just created a new table and insert all the result with the format in it... now this is not wrong but i got like millions of data... anyway divide points and close this...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.