Pregunta

I am trying to insert multiple rows via sql query scenario is this : There are multiple attributes against 1 testID and I want to copy attributes of one test to another test by giving their TestID here is the query I am trying but its not working at all

INSERT INTO dc_tp_attributes
(Attribute_name,acronym,active,description,testId,
subdepartmentid,
DOrder,Attribute_type,D_A_formula,D_A_formula_desc,
Linesno,DefaultValue,interfaced,ClientID,Enteredby,
Enteredon,drived,parentid,heading,print,interfaceid)

select Attribute_name,acronym,active,description,
635,subdepartmentid,DOrder,Attribute_type,D_A_formula,
D_A_formula_desc,Linesno,DefaultValue,interfaced,
ClientID,Enteredby,Enteredon,drived,parentid,
heading,print,interfaceid
FROM dc_tp_attributes
Where testid=877

Here I am copying attributes of testID=877 to testID=635, test with ID 877 has 10 attributes and test with testID 635 have just 1. There is an Autoincrement Primery Key Named AttributeID and the error is

"Field 'AttributeID' doesn't have a default value"
¿Fue útil?

Solución

Remove the extra parenthesis from the SELECT:

INSERT INTO dc_tp_attributes
(Attribute_name,... interfaceid)

select Attribute_name, ... interfaceid
FROM dc_tp_attributes
Where testid=877
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top