Click here to Skip to main content
16,011,444 members
Home / Discussions / Database
   

Database

 
GeneralRe: Display Row Number Pin
Jason Weibel10-Oct-02 10:03
Jason Weibel10-Oct-02 10:03 
GeneralRe: Display Row Number Pin
Robby10-Oct-02 10:35
Robby10-Oct-02 10:35 
GeneralRe: Display Row Number Pin
Carlos Antollini10-Oct-02 10:44
Carlos Antollini10-Oct-02 10:44 
GeneralRe: Display Row Number Pin
Rein Hillmann14-Oct-02 22:30
Rein Hillmann14-Oct-02 22:30 
GeneralRe: Display Row Number Pin
Rein Hillmann14-Oct-02 22:50
Rein Hillmann14-Oct-02 22:50 
QuestionCan I SELECT information the same time i INSERT Pin
Robby10-Oct-02 9:04
Robby10-Oct-02 9:04 
AnswerRe: Can I SELECT information the same time i INSERT Pin
David Salter10-Oct-02 9:56
David Salter10-Oct-02 9:56 
AnswerRe: Can I SELECT information the same time i INSERT Pin
Jon Hulatt10-Oct-02 22:05
Jon Hulatt10-Oct-02 22:05 
Indeed, using a stored procedure would by far and away be the best solution.

after an insert, sql server special variable @@IDENTITY contains the new pk of what you just inserted. so this will probably work:-

sqlInsert = "INSERT into OnlineAccess(userID,lastName,firstName,...) values('"&userID&"','"&lastName&"','"&firstName&"',...) ; SELECT @@IDENTITY AS [newkeyname]"

RS = MyConn.Execute(sqlInsert)
requestID = RS("newkeyname")


But really thats a bag of sh!t of an implementation. Stored procedures are the way to go. Why?

1. stored procedures run much quicker, because they are precompiled.
2. They are like functions in proper languages; you can change the internal code without changing the interface.

You could most probably do the whole job in one SP, like this:

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [p_YourProc]
 @UserId int,
 @Firstname varchar(100),
 @Lastname varchar(100),
 @NewPKout integer output

AS

-- define a sql variable
declare @NewPK int;

-- do the main insert first.
INSERT into OnlineAccess(userID,lastName,firstName) values
( @UserId, @LastName, @Firstname);

-- retrieve the new key
select @NewPK=@@IDENTITY;

-- do the other inserts
INSERT into DateTime (requestID,status) 
values(@NewPK,'OPEN')

-- might as well send the pk back to asp
set @NewPKout = @NewPK

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


There. Bob's your uncle.

Signature space for rent. Apply by email to....
GeneralADO Command->Execute throws exception Pin
ssirisha10-Oct-02 5:55
ssirisha10-Oct-02 5:55 
GeneralRe: ADO Command->Execute throws exception Pin
Carlos Antollini10-Oct-02 6:22
Carlos Antollini10-Oct-02 6:22 
GeneralRe: ADO Command->Execute throws exception Pin
ssirisha10-Oct-02 7:01
ssirisha10-Oct-02 7:01 
GeneralRe: ADO Command->Execute throws exception Pin
Carlos Antollini10-Oct-02 8:20
Carlos Antollini10-Oct-02 8:20 
QuestionHow to select 1 entry without using "top 1" in SQL query? Pin
Segal8-Oct-02 14:47
Segal8-Oct-02 14:47 
AnswerRe: How to select 1 entry without using "top 1" in SQL query? Pin
Paul Riley8-Oct-02 14:54
Paul Riley8-Oct-02 14:54 
GeneralRe: How to select 1 entry without using "top 1" in SQL query? Pin
Anonymous8-Oct-02 16:19
Anonymous8-Oct-02 16:19 
GeneralRe: How to select 1 entry without using "top 1" in SQL query? Pin
Jon Hulatt9-Oct-02 0:34
Jon Hulatt9-Oct-02 0:34 
GeneralRe: How to select 1 entry without using "top 1" in SQL query? Pin
Nick Parker9-Oct-02 1:43
protectorNick Parker9-Oct-02 1:43 
QuestionUpdating Access Queries using SQL? Pin
Paul Riley8-Oct-02 14:24
Paul Riley8-Oct-02 14:24 
AnswerRe: Updating Access Queries using SQL? Pin
Mazdak9-Oct-02 9:21
Mazdak9-Oct-02 9:21 
GeneralRe: Updating Access Queries using SQL? Pin
Paul Riley9-Oct-02 11:45
Paul Riley9-Oct-02 11:45 
AnswerRe: Updating Access Queries using SQL? Pin
Mazdak9-Oct-02 23:12
Mazdak9-Oct-02 23:12 
GeneralRe: Updating Access Queries using SQL? Pin
Paul Riley9-Oct-02 23:36
Paul Riley9-Oct-02 23:36 
GeneralOutput Nested Set Model to XML using MS SQL2K Pin
Ingram Leedy8-Oct-02 9:34
Ingram Leedy8-Oct-02 9:34 
Generalreading Excel from ASP.NET Pin
ViteshAggarwal8-Oct-02 2:39
ViteshAggarwal8-Oct-02 2:39 
GeneralRe: reading Excel from ASP.NET Pin
Ed Gadziemski8-Oct-02 4:46
professionalEd Gadziemski8-Oct-02 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.