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. SQL Stored Procedure push in the right direction :)

SQL Stored Procedure push in the right direction :)

Scheduled Pinned Locked Moved Database
databasesharepoint
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.
  • C Offline
    C Offline
    cdietschrun
    wrote on last edited by
    #1

    So I am working on this SP for my DB at work:

    CREATE PROCEDURE dbo.sp_CreateChecklistForPackage
    (
    @PACKAGE varchar(255)
    )
    AS

    INSERT INTO TBL_SWBOM_CHECKLISTS
    (
    PACKAGE,
    TEMPLATEOWNER,
    STEPNUMBER,
    STEPNAME,
    DESCRIPTION,
    LASTCHANGE,
    LASTCHANGEBY
    )
    select
    @PACKAGE,
    TEMPLATEOWNER,
    STEPNUMBER,
    STEPNAME,
    DESCRIPTION,
    LASTCHANGE,
    LASTCHANGEBY
    FROM TBL_SWBOM_CHECKLIST_TEMPLATES
    GO

    What I need it to do is find the newest entry for each of the three users (specific names that I can test against, like "TEMPLATEOWNER='Joe Smith') and put only that template into the SWBOM_CHECKLISTS table only. So the TBL_SWBOM_CHECKLISTS table should have one entry per package made up of three. So basically I need it to find the newest entry from each of the three user's separate entries and then put that into the other table. I think it's fairly simple and doable, just not 100% sure.

    M 1 Reply Last reply
    0
    • C cdietschrun

      So I am working on this SP for my DB at work:

      CREATE PROCEDURE dbo.sp_CreateChecklistForPackage
      (
      @PACKAGE varchar(255)
      )
      AS

      INSERT INTO TBL_SWBOM_CHECKLISTS
      (
      PACKAGE,
      TEMPLATEOWNER,
      STEPNUMBER,
      STEPNAME,
      DESCRIPTION,
      LASTCHANGE,
      LASTCHANGEBY
      )
      select
      @PACKAGE,
      TEMPLATEOWNER,
      STEPNUMBER,
      STEPNAME,
      DESCRIPTION,
      LASTCHANGE,
      LASTCHANGEBY
      FROM TBL_SWBOM_CHECKLIST_TEMPLATES
      GO

      What I need it to do is find the newest entry for each of the three users (specific names that I can test against, like "TEMPLATEOWNER='Joe Smith') and put only that template into the SWBOM_CHECKLISTS table only. So the TBL_SWBOM_CHECKLISTS table should have one entry per package made up of three. So basically I need it to find the newest entry from each of the three user's separate entries and then put that into the other table. I think it's fairly simple and doable, just not 100% sure.

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Well, it is easy enough to find the newest entry for a given owner in your setup:

      SELECT TOP 1 *
      FROM TBL_SWBOM_CHECKLIST_TEMPLATES
      WHERE LASTCHANGEBY = 'Joe Smith'
      ORDER BY LASTCHANGE DESC

      Wrap something like that in your INSERT and you should be good to go, at least for the first of your three records.

      MishaInTheCloud.blogspot.com

      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