@@IDENTITY correct syntax?
From: Mike (mikekelly100_at_hotmail.com)
Date: 12/13/03
- Next message: gnazio: "Re: @@IDENTITY correct syntax?"
- Previous message: Mike: "puzzled - can't write to database table"
- Next in thread: gnazio: "Re: @@IDENTITY correct syntax?"
- Reply: gnazio: "Re: @@IDENTITY correct syntax?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Dec 2003 07:44:37 -0800
Hi,
I am new to MS SQL and JSP and am having trouble finding documentation
or code examples for this feature.
I do an INSERT into a table with an IDENTITY column, then want to
retrieve the value from the incremented IDENTITY column in the row
I've just created. (Called "threadID".) I then insert "threadID"'s
value into another table.
Does the following appear correct? (And should I be using
SCOPE_IDENTITY instead of @@IDENTITY?)
// insert new thread
String threadQuery = "insert into threads (forumID, threadTitle,
views) values ('"+forumID+"','"+threadTitle+"','"+views+"') select
@@IDENTITY as 'Identity'";
myStatement.executeUpdate(threadQuery);
ResultSet rs = myStatement.GetResultSet();
int threadID = rs.getInt("Identity");
// insert new post
String postsQuery = "insert into posts (threadID, forumID, userName,
comments, submitDate, picURL, picCaption) values
('"+threadID+"','"+forumID+"','"+userName+"','"+comments+"','"+submitDate+"','"+imageURL+"','"+imageCaption+"')";
myStatement.executeUpdate(postsQuery);
Thanks,
Mike
- Next message: gnazio: "Re: @@IDENTITY correct syntax?"
- Previous message: Mike: "puzzled - can't write to database table"
- Next in thread: gnazio: "Re: @@IDENTITY correct syntax?"
- Reply: gnazio: "Re: @@IDENTITY correct syntax?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]