Hi there,
I'm using Dynamic Forms to capture some data and I'm trying to set up a conditional data capture. I have the user entering a zip code and if the zip is in my table, then the data gets populated in table_X, but if it's not in the zip table, then it gets populated in table_Y.
I'm no longer getting errors, but the data does not seem to be going into the table. Any help with this is appreciated. Here is my current code:
SELECT zip = CASE WHEN zip = 12345 THEN 'INSERT INTO table_X (name,email,zip) VALUES ($(name),$(email),$(zipcode))' ELSE 'INSERT INTO table_Y (name,email,zip) VALUES ($(name),$(email),$(zipcode))' END FROM zipcodes;
I've had previous attempts at this and the respective errors are below each:
Try #1: SELECT zip FROM zipcodes CASE WHEN zip = '12345' THEN INSERT INTO table_X (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)') ELSE INSERT INTO TESTtable_Y (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)') END ;
Incorrect syntax near the keyword 'CASE'. Incorrect syntax near the keyword 'ELSE'..
Try #2: SELECT zip = CASE WHEN zip = 12345 THEN INSERT INTO table_X (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)') ELSE INSERT INTO table_Y (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)') END FROM zipcodes;
Incorrect syntax near the keyword 'INSERT'. Incorrect syntax near the keyword 'ELSE'. Incorrect syntax near the keyword 'FROM'.
Try #3: SELECT zip = CASE WHEN zip = 12345 THEN 'INSERT INTO table_X (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)')' ELSE 'INSERT INTO table_Y (name,email,zip) VALUES ('$(name)','$(email)','$(zipcode)')' END FROM zipcodes;
Incorrect syntax near '$(name)'.
Thanks much!
-Jahn
|