I am trying to write a stored procedure in T-SQL that inserts a record into a table, then is supposed to return the primary key (EmpID) for that record as an output parameter. How I'm trying to do that is by using a trigger on the table's insert command that retreives the EmpID parameter out of the inserted table, and uses a SELECT into to put it into another table. Based on what I have, the following will work and return the appropriate value:
The hangup is that in the stored procedure the query normally runs in, I need a way to tell it to drop the table if it exists. Is there some way I could return a 0 or 1 value to determine if the table exists or not to put in this?
Code:
drop table tblTemp
declare @empidout int
insert into Employee (Title, FirstName, MiddleName, LastName,
BirthDate, HireDate, Salary) values ('Doctor of German Repairs', 'Otto', null,
'Partz', '02-23-75', '01-01-2003', 65000)
set @empidout = (select EmpID from tblTemp)
select @empidout
The hangup is that in the stored procedure the query normally runs in, I need a way to tell it to drop the table if it exists. Is there some way I could return a 0 or 1 value to determine if the table exists or not to put in this?
Code:
if @tblExists = '0'
drop table tblTemp