Append Query Using MAX()

J

Jumping Matt Flash

I'm trying to achieve the following SQL in an access database. However i'm
having trouble porting my SQL to a suitable format which Access understands.

I'm trying to insert a row which has two columns, one is a value which is
assigned using my VB .NET application, the other one is the result of a SQL
function MAX. I.e.

INSERT INTO tblTable(column1, column2) VALUES ('string1', (SELECT
MAX(column2)+1 As column2 FROM tblTable))

For some reason tho whenever I use this syntax, i keep getting an syntax
error returned. I've tried using the query builder tool and i then have
trouble with the function MAX

TIA
Matt
 
P

peregenem

Jumping said:
I'm trying to insert a row which has two columns, one is a value which is
assigned using my VB .NET application, the other one is the result of a SQL
function MAX. I.e.

INSERT INTO tblTable(column1, column2) VALUES ('string1', (SELECT
MAX(column2)+1 As column2 FROM tblTable))

Try

INSERT INTO tblTable (column1, column2)
SELECT 'string1' AS column1,
MAX(column2) + 1 As column2,
FROM tblTable
 
J

Jeff Boyce

Why? As in "why are you trying to store a calculated value?"

If you can derive the calculated value via a query, is there a business need
you're filling by also storing it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top