Jump to content

Select Everything Before a Character


Nathan

Recommended Posts

Here we go, just figured this one out:

 

select replace(left(order_items,LOCATE('x',order_items)),'x','')

You should post a tutorial explaining this whole thing ;) what it does and what it is used for. I see you are good at coding stuff :) wish I had that knowlage :)

Link to comment
Share on other sites

You should post a tutorial explaining this whole thing :) what it does and what it is used for. I see you are good at coding stuff :P wish I had that knowlage :)

 

try:

left(order_items,instr(order_item,'x')). This should be a little more efficient. Basically, left() in MSSQL takes the characters in a string from starting position on the left to an integer. INSTR determines the integer location of a character (x). So it takes all the characters on the left from beginning to first X

 

This assumes that there is only one x as well. Do you need to trim the string or anything?

Link to comment
Share on other sites

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.   Paste as plain text instead

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