![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||||||
| |||||||
|
|
How do I change a table column to have NULL default values? This doesn't work: ALTER TABLE cart_order modify column cart_inventory DEFAULT NULL |
|
I am trying to write this function to update the error_flag=1 when there is either a NULL or a ' ' in the inventory.ndc column. This is the match field to the link.ndc column. I should also find all the records where there IS an inventory.ndc value but there is no match in the link table for example, if the i.ndc is wrong. |
|
Do you have to link to the table on every function in a php page or is once enough? |
|
I'm not getting this function to work as it is without the left join? |
|
The $link is the mysql_connect("server:,"user","pwd"); |
|
The rest of it should be something like AND there is no match in the l.ndc table. |
|
tia, function setErrorFlag($link) { mysql_select_db("cart_order",'$link'); "UPDATE cart_order.cart_inventory as i //LEFT JOIN cart_order.link AS l ON i.ndc =l.ndc SET i.error_flag=1 WHERE i.ndc =' ' OR i.ndc IS NULL"; } |
#3
| |||
| |||
|
|
In article <30da0552-b536-4eba-8017-ff372432c... (AT) u17g2000prd (DOT) googlegroups..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: How do I change a table column to have NULL default values? *This doesn't work: ALTER TABLE cart_order modify column cart_inventory DEFAULT NULL http://dev.mysql.com/doc/refman/5.1/en/alter-table.html You want to use ALTER COLUMN instead of MODIFY COLUMN, e.g. ALTER TABLE cart_order ALTER COLUMN cart_inventory SET DEFAULT NULL; I am trying to write this function to update the error_flag=1 * when there is either a NULL or a ' ' in the inventory.ndc *column. *This is the match field to the link.ndc column. * I should also find all the records where there IS an inventory.ndc value but there is no match in the link table for example, if the i.ndc is wrong. Okay..... Do you have to link to the table on every function in a php page or is once enough? I have no idea what you mean by this. I'm not getting this function to work as it is without the left join? I don't know, are you? Why are you asking *us* if you're getting it to work? We can't see what's happening... The $link is the mysql_connect("server:,"user","pwd"); Why do you imagine that is related in any way to whether your UPDATE statement is correct? The rest of it should be something like AND there is no match in the l.ndc table. OK, so put some code in there that tests for a match. You mean the l.ndc *column*, BTW. tia, function setErrorFlag($link) { * * * *mysql_select_db("cart_order",'$link'); * * * *"UPDATE cart_order.cart_inventory as i * * * *//LEFT JOIN cart_order.link AS l ON i.ndc =l.ndc * * * *SET i.error_flag=1 WHERE i.ndc =' ' OR i.ndc IS NULL"; * * * *} The LEFT JOIN has no effect here, even if it's not commented out, becausethe WHERE clause doesn't test any conditions involving the second table. You need to add such a condition. Okay, sorry about that I was asking a question relating to PHP and the |
#4
| |||
| |||
|
|
On Jun 19, 1:02=A0pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote: In article <30da0552-b536-4eba-8017-ff372432c... (AT) u17g2000prd (DOT) googlegroups= ..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: How do I change a table column to have NULL default values? This doesn't work: ALTER TABLE cart_order modify column cart_inventory DEFAULT NULL http://dev.mysql.com/doc/refman/5.1/en/alter-table.html You want to use ALTER COLUMN instead of MODIFY COLUMN, e.g. ALTER TABLE cart_order ALTER COLUMN cart_inventory SET DEFAULT NULL; I am trying to write this function to update the error_flag=1 when there is either a NULL or a ' ' in the inventory.ndc column. This is the match field to the link.ndc column. I should also find all the records where there IS an inventory.ndc value but there is no match in the link table for example, if the i.ndc is wrong. Okay..... Do you have to link to the table on every function in a php page or is once enough? I have no idea what you mean by this. I'm not getting this function to work as it is without the left join? I don't know, are you? Why are you asking *us* if you're getting it to work? We can't see what's happening... The $link is the mysql_connect("server:,"user","pwd"); Why do you imagine that is related in any way to whether your UPDATE statement is correct? The rest of it should be something like AND there is no match in the l.ndc table. OK, so put some code in there that tests for a match. You mean the l.ndc *column*, BTW. tia, function setErrorFlag($link) { mysql_select_db("cart_order",'$link'); "UPDATE cart_order.cart_inventory as i //LEFT JOIN cart_order.link AS l ON i.ndc = l.ndc SET i.error_flag=1 WHERE i.ndc =' ' OR i.ndc IS NULL"; } The LEFT JOIN has no effect here, even if it's not commented out, because the WHERE clause doesn't test any conditions involving the second table. You need to add such a condition. Okay, sorry about that I was asking a question relating to PHP and the $link. I don't know if you have to link to the server in each function in a php page or once in the beginning is enough when you are doing other sql queries? |
|
By the way, the ALTER table didn't work because text fields can't be changed to NULL so I only have to look for ' ' empty rows. All the inventory columns are text because it is an upload from a csv file. |
|
Regarding the left join condition. Would that be in a subquery where the i.ndc != l.ndc UPDATE cart_order.cart_inventory as i SET i.error_flag=1 WHERE i.ndc= ' ' (LEFT JOIN cart_order.link as l WHERE i.ndc!=l.ndc) |
#5
| |||
| |||
|
|
In article <2fa425db-d9d2-4e36-bb29-dce58171d822 (AT) e34g2000pra (DOT) googlegroups.com>, JRough <jlrough (AT) yahoo (DOT) com> wrote: On Jun 19, 1:02=A0pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote: In article <30da0552-b536-4eba-8017-ff372432c... (AT) u17g2000prd (DOT) googlegroups= ..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: How do I change a table column to have NULL default values? This doesn't work: ALTER TABLE cart_order modify column cart_inventory DEFAULT NULL http://dev.mysql.com/doc/refman/5.1/en/alter-table.html You want to use ALTER COLUMN instead of MODIFY COLUMN, e.g. ALTER TABLE cart_order ALTER COLUMN cart_inventory SET DEFAULT NULL; I am trying to write this function to update the error_flag=1 when there is either a NULL or a ' ' in the inventory.ndc column. This is the match field to the link.ndc column. I should also find all the records where there IS an inventory.ndc value but there is no match in the link table for example, if the i.ndc is wrong. Okay..... Do you have to link to the table on every function in a php page or is once enough? I have no idea what you mean by this. I'm not getting this function to work as it is without the left join? I don't know, are you? Why are you asking *us* if you're getting it to work? We can't see what's happening... The $link is the mysql_connect("server:,"user","pwd"); Why do you imagine that is related in any way to whether your UPDATE statement is correct? The rest of it should be something like AND there is no match in the l.ndc table. OK, so put some code in there that tests for a match. You mean the l.ndc *column*, BTW. tia, function setErrorFlag($link) { mysql_select_db("cart_order",'$link'); "UPDATE cart_order.cart_inventory as i //LEFT JOIN cart_order.link AS l ON i.ndc = l.ndc SET i.error_flag=1 WHERE i.ndc =' ' OR i.ndc IS NULL"; } The LEFT JOIN has no effect here, even if it's not commented out, because the WHERE clause doesn't test any conditions involving the second table. You need to add such a condition. Okay, sorry about that I was asking a question relating to PHP and the $link. I don't know if you have to link to the server in each function in a php page or once in the beginning is enough when you are doing other sql queries? That depends on how your functions are written. This is a separate issue, however, and really should be addressed in a separate thread. By the way, the ALTER table didn't work because text fields can't be changed to NULL so I only have to look for ' ' empty rows. All the inventory columns are text because it is an upload from a csv file. No, your ALTER TABLE command didn't work because you had the syntax wrong. Didn't you read what I posted above? Regarding the left join condition. Would that be in a subquery where the i.ndc != l.ndc UPDATE cart_order.cart_inventory as i SET i.error_flag=1 WHERE i.ndc= ' ' (LEFT JOIN cart_order.link as l WHERE i.ndc!=l.ndc) No. That's not syntactically valid. You might try something like WHERE i.ndc = ' ' OR i.ndc IN (SELECT blah-blah-blah) Replace the blah-blah-blah inside the parentheses with an appropriate SELECT statement to locate the condition(s) on which you want to match i.ndc to l.ndc. |
#6
| |||
| |||
|
|
In article <2fa425db-d9d2-4e36-bb29-dce58171d... (AT) e34g2000pra (DOT) googlegroups..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: On Jun 19, 1:02=A0pm, spamb... (AT) milmac (DOT) com (Doug Miller) wrote: In article <30da0552-b536-4eba-8017-ff372432c... (AT) u17g2000prd (DOT) googlegroups= ..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: How do I change a table column to have NULL default values? This doesn't work: ALTER TABLE cart_order modify column cart_inventory DEFAULT NULL http://dev.mysql.com/doc/refman/5.1/en/alter-table.html You want to use ALTER COLUMN instead of MODIFY COLUMN, e.g. ALTER TABLE cart_order ALTER COLUMN cart_inventory SET DEFAULT NULL; I am trying to write this function to update the error_flag=1 when there is either a NULL or a ' ' in the inventory.ndc column. This is the match field to the link.ndc column. I should also find all the records where there IS an inventory.ndc value but there is no match in the link table for example, if the i.ndc is wrong. Okay..... Do you have to link to the table on every function in a php page or is once enough? I have no idea what you mean by this. I'm not getting this function to work as it is without the left join? I don't know, are you? Why are you asking *us* if you're getting it towork? We can't see what's happening... The $link is the mysql_connect("server:,"user","pwd"); Why do you imagine that is related in any way to whether your UPDATE statement is correct? The rest of it should be something like AND there is no match in the l.ndc table. OK, so put some code in there that tests for a match. You mean the l.ndc *column*, BTW. tia, function setErrorFlag($link) { * *mysql_select_db("cart_order",'$link'); * *"UPDATE cart_order.cart_inventory as i * *//LEFT JOIN cart_order.link AS l ON i.ndc = l.ndc * *SET i.error_flag=1 WHERE i.ndc =' ' OR i.ndc IS NULL"; * *} The LEFT JOIN has no effect here, even if it's not commented out, because the WHERE clause doesn't test any conditions involving the second table. You need to add such a condition. Okay, sorry about that I was asking a question relating to PHP and the $link. I don't know if you have to link to the server in each function in a php page or once in the beginning is enough when you are doing other sql queries? That depends on how your functions are written. This is a separate issue, however, and really should be addressed in a separate thread. By the way, the ALTER table didn't work because text fields can't be changed to NULL so I only have to look for ' ' empty rows. *All the inventory columns are text because it is an upload from a csv file. No, your ALTER TABLE command didn't work because you had the syntax wrong.. Didn't you read what I posted above? Regarding the left join condition. *Would that be in a subquery where the i.ndc != l.ndc UPDATE cart_order.cart_inventory as i SET i.error_flag=1 WHERE i.ndc= ' ' (LEFT JOIN cart_order.link as l WHERE i.ndc!=l.ndc) No. That's not syntactically valid. You might try something like WHERE i.ndc = ' ' OR i.ndc IN (SELECT blah-blah-blah) Replace the blah-blah-blah inside the parentheses with an appropriate SELECT statement to locate the condition(s) on which you want to match i.ndc to l.ndc. |
#7
| |||
| |||
|
|
I have to try this on Monday but I only want to flag what is not a match on the ndc in the two tables. So if there is no inventory.ndc (i) then I know there is no match in the link table. HOwever if there is a wrong i.ndc then there won't be a match so I don't know what the subquery SELECT would be. There most likely won't be but I would like to trap for it as it would be an erro. I guess it would be WHERE i.ndc = ' ' OR NOT IN(SELECT l.ndc from link as l) Something like that? |
|
I really thank you for your answer. |
#8
| |||
| |||
|
|
In article <323ca44d-699f-4ef3-b961-6e06e38e6... (AT) e34g2000pra (DOT) googlegroups..com>, JRough <jlro... (AT) yahoo (DOT) com> wrote: [...] I have to try this on Monday but I only want to flag what is not a match on the ndc in the two tables. So if there is no inventory.ndc (i) then I know there is no match in the link table. *HOwever if there is a wrong i.ndc then there won't be a match so I don't know what the subquery SELECT would be. There most likely won't be but I would like to trap for it as it would be an erro. *I guess it would be WHERE *i.ndc = ' ' OR NOT *IN(SELECT l.ndc from link as l) Something like that? Something very close to that, actually -- you have the syntax almost, butnot quite, correct. WHERE i.ndc = ' ' OR i.ndc NOT IN (SELECT l.ndc FROM link AS l) I really thank you for your answer. You're welcome. I hope this helps. |
![]() |
| Thread Tools | |
| Display Modes | |
| |