Professional Web Applications Themes

Query Help! - Microsoft SQL / MS SQL Server

Hello, I have a tempTable with the data I need, just one column. I need to put the entire column into another table. I need to put the FmeaID from the TempFmea table into the column FmeaID in the table called tblItem_FMEA_ViewDetails. I'm sorry for my ignorance, but I am somewhat new to this. Any help would be GREATLY APPRECIATED. Here is what the tblItem_FMEA_ViewDetails table looks like: GroupID (uniqueidentifier) FmeaID (int) UpdateUserID(char 20) UpdateTime (datetime) the groupID, UpdateUserID and UpdateTime will all be the same value during the insert. Here is my script to create the temp table CREATE ...

  1. #1

    Default Query Help!


    Hello, I have a tempTable with the data I need, just one column. I need
    to put the entire column into another table.
    I need to put the FmeaID from the TempFmea table into the column FmeaID
    in the table called tblItem_FMEA_ViewDetails. I'm sorry for my
    ignorance, but I am somewhat new to this. Any help would be GREATLY
    APPRECIATED.
    Here is what the tblItem_FMEA_ViewDetails table looks like:
    GroupID (uniqueidentifier)
    FmeaID (int)
    UpdateUserID(char 20)
    UpdateTime (datetime)
    the groupID, UpdateUserID and UpdateTime will all be the same value
    during the insert.
    Here is my script to create the temp table

    CREATE TABLE #TempFmea
    (FmeaID int)
    insert into #TempFmea

    Select FmeaID from tblItem_FMEA_ViewDetails F_VD
    inner join tblItem_Fmea_Views F_V on F_V.GroupID = F_VD.GroupID
    inner join tblSystemHierarchy SH on SH.UniqueID = F_V.UniqueID
    where SH.[Name] = 'Smoke Detection'--'Alarms77'

    Select * from #tempFmea
    --???Not sure how to insert entire column into tblItem_Fmea_ViewDetails
    GO
    Drop table #tempFmea
    GO

    --
    Posted via http://dbforums.com
    ksbrace Guest

  2. #2

    Default Re: Query Help!

    It is not totally clear to me what you want, but would this help (without
    using a temporary table)?:

    INSERT INTO tblItem_FMEA_ViewDetails (GroupID, FmeaID, UpdateUserID,
    UpdateTime )
    SELECT F_VD.GroupID, FmeaID , USER_NAME, GETDATE()
    from tblItem_FMEA_ViewDetails F_VD
    inner join tblItem_Fmea_Views F_V on F_V.GroupID = F_VD.GroupID
    inner join tblSystemHierarchy SH on SH.UniqueID = F_V.UniqueID
    where SH.[Name] = 'Smoke Detection'--'Alarms77'


    "ksbrace" <com> wrote in message
    news:com... 


    Jacco Guest

  3. #3

    Default Re: Query Help!


    Hello, I got it working ( not that anyone really cares ), but my
    question is: Can I make this more efficient/elegant and is there
    anything else I need to check with the cursor??? Thanks!!!!

    CREATE PROCEDURE dbo.usp_datFmea_Bulk_Copy
    (
    destUniqueID int,
    sourceUniqueID int,
    UpdateUserID char(20)

    )

    AS
    CREATE TABLE #TempFmea
    (FmeaID int)
    insert into #TempFmea

    Select FmeaID from tblItem_FMEA_ViewDetails F_VD
    inner join tblItem_Fmea_Views F_V on F_V.GroupID = F_VD.GroupID
    inner join tblSystemHierarchy SH on SH.UniqueID = F_V.UniqueID
    where SH.UniqueID = sourceUniqueID

    --------------------
    declare fmeaCursor cursor for
    Select FmeaID from #tempFmea
    for read only
    declare tempFmeaID int

    open fmeaCursor
    fetch next from fmeaCursor into tempFmeaID


    Declare newGroupID uniqueidentifier
    IF NOT EXISTS(SELECT * from dbo.tblItem_FMEA_Views

    WHERE UniqueID = destUniqueID)

    BEGIN
    SET newGroupID = newID();
    end

    ELSE

    BEGIN

    SET newGroupID =
    (SELECT groupID FROM dbo.tblItem_FMEA_Views
    WHERE UniqueID = destUniqueID)

    END
    /*
    if (fetch_status = -1)
    begin
    close fmeaCursor
    deallocate fmeaCursor
    end
    */
    while (fetch_status = 0)
    begin
    DECLARE UpdateTime datetime
    set updateTime = getdate()
    --FMEA_Views
    INSERT INTO dbo.tblItem_FMEA_Views(UniqueID, GroupID, UpdateUserID,
    UpdateTime)

    VALUES(destUniqueID, newGroupID, UpdateUserID, cast(UpdateTime
    as datetime) );


    --FMEA_ViewDetails
    INSERT INTO dbo.tblItem_FMEA_ViewDetails (GroupID, FmeaID,
    UpdateUserID, UpdateTime)

    VALUES( newGroupID, tempFmeaID, updateUserID, cast(UpdateTime
    as datetime) );

    ----------------------------------------
    fetch next from fmeaCursor into tempFmeaID
    end
    close fmeaCursor
    deallocate fmeaCursor

    Drop table #tempFmea
    GO

    --
    Posted via http://dbforums.com
    ksbrace Guest

Similar Threads

  1. Creating data query from mySQL stored query!?
    By johnegbert in forum Coldfusion Database Access
    Replies: 2
    Last Post: August 5th, 09:28 PM
  2. Query of Queries with constructed query using QueryNew()and QueryAddRow()
    By LeadFoot in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: August 4th, 02:00 PM
  3. Query of Queries on query New type query
    By david_h in forum Coldfusion Database Access
    Replies: 2
    Last Post: May 6th, 08:55 PM
  4. CAML Query: Multiple Query Fields Issue
    By Jon F. in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 12th, 08:19 PM
  5. Replies: 1
    Last Post: July 2nd, 09:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139