• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sybase database - insert statement problems

 
vandu matcha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table(CODE_LOOKUP) with 3 columns(CL_ID,CL_RC,CL_DESC)

i wanted to insert a new column taking the max(id)+1

This is the sql query i am trying to insert

INSERT INTO CODE_LOOKUP(CL_ID,CL_RC,CL_DESC)
values(max(CL_ID)+1, 'Region0', 'Region0');

I couldnot execute the Query..it throws me out saying
com.sybase.jdbc2.jdbc.SybSQLException: The name 'CL_ID' is illegal in this context. Only constants, constant expressions, or variables allowed here. Column names are illegal.

what is the correct way or Is there any other way i can insert the column into the database...
 
Campbell Ritchie
Sheriff
Posts: 51461
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is too late to put an autoincrement on CL_ID, I presume?

How about a stored procedure which sets a variable to the value from max(CL_ID), then puts the value (+1) back in the column later?

Anybody else got any ideas?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic