Jump to content

SELECTQUERY, make 1 column into 2 columns


jeroenvanveghel

Recommended Posts

Hi guys and girls!

I'm new at mysql so please help me out.

 

I have 1 table, consisting of three rows:

number, description, relationNumber.

 

and i want to query the following on this table:

SELECT number, description, 

CONCAT( MOD( relationNumber , 100) , SIGNED)) AS relationCode, 
CONCAT (MOD( ( relationNumber / 100) , 100 ) , SIGNED ) as relationCodeExtra

FROM erwin.relatiecode r;

 

anyway this is giving me the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), CONCAT (MOD( (relationNumber  / 100) , 100 ) , SIGNED ) as rel' 

 

So what i'm trying to accomplish is to split one column into 2 columns.

Is this possible in MYSQL? Because my code isn't flexible enough.

 

Thanks for reading my post! And double thanks if you can give me an answer!

Link to comment
Share on other sites

Why don't you try this?

SELECT number, description, 
MOD( relationNumber , 100)  AS relationCode, 
MOD(relationNumber / 100 , 100 )  as relationCodeExtra

FROM erwin.relatiecode r;

 

That works actually, but the problem is the integer is not signed then. I need that because i want 'whole'  numbers only (don't know the phrase to say it in English).

So when i rewrite it to this:

SELECT number, number,
MOD( (relationNumber , 100), SIGNED)  AS relationCode,
MOD( (relationNumber / 100 , 100 ), SIGNED)  AS relationCodeExtra

FROM erwin.relatiecode r;

I receive the following error:

Operand should contain 1 column(s)          errorNr: 1241.

Not sure why this happens.

Link to comment
Share on other sites

That works actually, but the problem is the integer is not signed then. I need that because i want 'whole'  numbers only (don't know the phrase to say it in English).

 

For future reference, an integer is a whole number.

 

If you just want the integer part then you can use FLOOR, CEIL or ROUND Mysql functions.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.