Administrators Nathan Posted February 23, 2012 Administrators Share Posted February 23, 2012 So I could do this in MSSQL, but how is this done in MYSQL? I data in field "order_items" like: 121x1 134x4 1001x2 163x1 What I want to do is select everything before the "x". Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted February 23, 2012 Author Administrators Share Posted February 23, 2012 Here we go, just figured this one out: select replace(left(order_items,LOCATE('x',order_items)),'x','') Quote Link to comment Share on other sites More sharing options...
Shole Posted February 24, 2012 Share Posted February 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
haye55987 Posted February 25, 2012 Share Posted February 25, 2012 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 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? Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted February 25, 2012 Author Administrators Share Posted February 25, 2012 Yeah I ended up using your example haye. There is only 1 x in the data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.