I have this SQL SELECT statement:
INSERT INTO customer (custFirstName, custMiddleInitial, custLastName, custAddress1, custAddress2, custCity, custState, custZip, custBusiness, custEmailAddress, custID, custUserName, custPassword, custStatus) VALUES('Bob' , 'A ', 'Smith' , '423 W Summit St' , 'NA' , 'Chicago' , 'IL' , '60641' , 'bob.org' , 'bob@test.com', 1
, 'bob' , 'enter','active')
For the custID, I want it to automatically do a count of the current customer ID's in the table and then increment that count by 1, and use that for the value.
To do the count I know its this statement: SELECT count(custID) from customer
Then I want to take that output and add one to it and use that number in the INSERT INTO statement. This is for a web application I am doing. I know I can do two database calls, doing the count SELECT statement first and storing the value in a variable. Then use that variable for the custID field in the INSERT INTO statement. I wondering though if there is some type of subquery or something I can do where I can make it one statement.
INSERT INTO customer (custFirstName, custMiddleInitial, custLastName, custAddress1, custAddress2, custCity, custState, custZip, custBusiness, custEmailAddress, custID, custUserName, custPassword, custStatus) VALUES('Bob' , 'A ', 'Smith' , '423 W Summit St' , 'NA' , 'Chicago' , 'IL' , '60641' , 'bob.org' , 'bob@test.com', 1
, 'bob' , 'enter','active')
For the custID, I want it to automatically do a count of the current customer ID's in the table and then increment that count by 1, and use that for the value.
To do the count I know its this statement: SELECT count(custID) from customer
Then I want to take that output and add one to it and use that number in the INSERT INTO statement. This is for a web application I am doing. I know I can do two database calls, doing the count SELECT statement first and storing the value in a variable. Then use that variable for the custID field in the INSERT INTO statement. I wondering though if there is some type of subquery or something I can do where I can make it one statement.