Administrators Nathan Posted February 23, 2012 Administrators 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
Administrators Nathan Posted February 23, 2012 Author Administrators Posted February 23, 2012 Here we go, just figured this one out: select replace(left(order_items,LOCATE('x',order_items)),'x','') Quote
Shole Posted February 24, 2012 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
haye55987 Posted February 25, 2012 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
Administrators Nathan Posted February 25, 2012 Author Administrators Posted February 25, 2012 Yeah I ended up using your example haye. There is only 1 x in the data. Quote
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.