Click here to Skip to main content
15,937,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to insert some values to a new table based on another table fields value..
any one know about the correct syntax for that please help me..

i used this syntax .i know this is not valid.

INSERT INTO tbl_cust_payments
VALUES(null,'" + dates + "','" + sub_id + "','" + cust_no + "','" + amount + "')
WHERE NOT EXISTS (SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount <= 0)

tbl_cust_payments and tbl_subscriber_account are the two tables..

Try like this.
INSERT INTO tbl_temp2 (fld_id)
  SELECT tbl_temp1.fld_order_id
  FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

for more details check this website[^][^][^]
Share this answer
sabodh 19-Jul-13 3:41am    
thanks for the reply..
but i don't need the values from another table to insert i need to insert the values manually..
suggested codes are copy the values from another tables..
but i use the textfieds values from the UI..
syed shanu 19-Jul-13 3:51am    
yes you can insert any value It might be your own values or from the selected table values.
for example here i have a insert query with my own insert values in select statement with condition.
insert into Subul1
SELECT '2013-07-12 00:00:00.000','S',10,10,40,40 from Subul WHERE GIMAC > 10;
Hi, try this:

IF NOT EXISTS(SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount <= 0)
    INSERT INTO tbl_cust_payments
    VALUES(null, dates, sub_id, cust_no, amount) 

Hope it helps! :)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900