Stored Procedure logic
-
I am using the following stored procedure to insert into two tables and it works fine ALTER PROCEDURE createEmployee(@loginId VARCHAR (20), @username VARCHAR (25), @passwrd VARCHAR (25),@empId VARCHAR (20),@title varchar(5),@branchNo VARCHAR(20),@Fname VARCHAR(50),@idNo VARCHAR(13),@physicaladdress varchar(50),@province VARCHAR(50),@city VARCHAR(50),@telephone varchar(15),@cellNo VARCHAR(15),@Email VARCHAR(30),@employeetype varchar(15),@salary NUMERIC(11,2)) AS INSERT INTO LoginInfo VALUES(@loginId,@username,@passwrd) --SET @loginId=@@IDENTITY INSERT INTO EMPLOYEE VALUES(@empId,@loginId,@title,@branchNo,@Fname,@idNo,@physicaladdress,@province,@city,@telephone,@cellNo,@Email,@employeetype,@salary); But Note the @branchNo parameter to be inserted into the EMPLOYEE table. I need to get it from a table named BRANCH based on some criteria. Currently I have hard coded its(@branch parameter)its value.I've tried to use the column level Select subquery but it is not allowed. please give a junior developer some logic
ML Lingwati
-
I am using the following stored procedure to insert into two tables and it works fine ALTER PROCEDURE createEmployee(@loginId VARCHAR (20), @username VARCHAR (25), @passwrd VARCHAR (25),@empId VARCHAR (20),@title varchar(5),@branchNo VARCHAR(20),@Fname VARCHAR(50),@idNo VARCHAR(13),@physicaladdress varchar(50),@province VARCHAR(50),@city VARCHAR(50),@telephone varchar(15),@cellNo VARCHAR(15),@Email VARCHAR(30),@employeetype varchar(15),@salary NUMERIC(11,2)) AS INSERT INTO LoginInfo VALUES(@loginId,@username,@passwrd) --SET @loginId=@@IDENTITY INSERT INTO EMPLOYEE VALUES(@empId,@loginId,@title,@branchNo,@Fname,@idNo,@physicaladdress,@province,@city,@telephone,@cellNo,@Email,@employeetype,@salary); But Note the @branchNo parameter to be inserted into the EMPLOYEE table. I need to get it from a table named BRANCH based on some criteria. Currently I have hard coded its(@branch parameter)its value.I've tried to use the column level Select subquery but it is not allowed. please give a junior developer some logic
ML Lingwati
How about:
INSERT INTO EMPLOYEE
SELECT
@empId,
@loginId,
@title,
branchNo,
@Fname,
@idNo,
@physicaladdress,
@province,
@city,
@telephone,
@cellNo,
@Email,
@employeetype,
@salary
FROM BRANCH
WHERE someCriteriaIn case thats a bit confusing, you can pull the branchNo from another table while still using all your variable for the other columns to be inserted.