Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Stored Procedure logic

Stored Procedure logic

Scheduled Pinned Locked Moved Database
databasecareer
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LucBite
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • L LucBite

      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

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      How about:

      INSERT INTO EMPLOYEE
      SELECT
      @empId,
      @loginId,
      @title,
      branchNo,
      @Fname,
      @idNo,
      @physicaladdress,
      @province,
      @city,
      @telephone,
      @cellNo,
      @Email,
      @employeetype,
      @salary
      FROM BRANCH
      WHERE someCriteria

      In 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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups