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.

Thanks
LVL 1
WeTiAsked:
Who is Participating?
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.
0
MishaProgrammerCommented:
What do you want to convert? Do you want to convert string to int?
In this case try this code
SELECT CONVERT(INT, number) FROM Table

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

0
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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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

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

0
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...
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.