How do i write INSERT statement if i get the values of colA from TableX, colB from TableY and colC from TableZ?
eg: INSERT INTO TableA (colA, colB, colC) VALUES (?,?
INSERT INTO TableA(colA, colB, colC)
SELECT TableX.valA, TableY.valB, TableZ.valC
FROM TableX
INNER JOIN TableY ON :......
INNER JOIN TableZ ON ........
Of course, TableX, TableY and TAbleZ might also be related in some other way (not INNER JOIN).
If you cannot find any relation between the tables AT ALL, you could also do three separate
SELECT @value1 = valA FROM TableX WHERE ......
SELECT @value2 = valB FROM TableY WHERE ......
SELECT @value3 = valC FROM TableZ WHERE ......
and then an insert like this:
INSERT INTO TableA(colA, colB, colC)
VALUES(@value1, @value2, @value3)
That's the ultimate last resort, you can can't express everything in a single SELECT
statement.
Marc