Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Given below is the code for a store

Status
Not open for further replies.

unicorn11

Programmer
Jun 10, 2000
392
IN
Given below is the code for a stored procedure

the table as a ID that is stored for a new record is created

i need to modify the code so that it returns the id of the new record entered


[red]
Code:
Create procedure SPW_NewSpec

  @sSpecName varchar (100),
  @sPass varchar (50),
  @dtCreate datetime

 as

  if exists(select * from Q14 where TX_SpecName = @sSpecName)
  begin
   return(0)
 end
else 
 begin
   insert into Q14 (TX_SpecName, TX_pass, DT_Create) 
   values (@sSpecName, @sPass, @dtCreate)
   return(1)
 end 

go
[/red]

Thanks in advance for your help
regards (-:
Unicorn11
unicorn11@mailcity.com

[red]Luck is not chance, it's toil; fortune's expensive smile is earned.[red]
 
Is the ID an identity field? If it is, you can use the @@identity global variable. It contains the last identity key assigned. If it's not an identity, you could return the result of select max(id) from Q14.
 
You may also want to use an OUTPUT parameter and return that instead of a literal value. JHall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top