Stored Procedure

Results 1 to 2 of 2

Thread: Stored Procedure

  1. #1
    Join Date
    Dec 1969

    Default Stored Procedure

    Can someone help me write a stored procedure? I know how to do the following in asp, but I&#039;m completely lost with stored procedures.<BR><BR>I have two tables (table1 and table2) that have identical column names and generally identical content. I need to update table1 with the data from table2 (the odd field may have changed here and there) and if a record does not exist, I need to add it.<BR><BR>Thanks in advance for your help. If you have any great online resources to point me to for writing stored procedures, that would be awesome!

  2. #2
    Join Date
    Dec 1969
    Indianapolis, IN

    Default RE: Stored Procedure

    Okay, for the update, do:<BR>UPDATE table1 SET field1 = T2.field1 ...<BR>FROM table2 T2<BR>WHERE table1.Keyfield = T2.Keyfield<BR><BR>Then, do an insert like this:<BR>INSERT INTO table1<BR>SELECT * FROM table2<BR>WHERE table2.Keyfield IN <BR>&nbsp;&nbsp;(SELECT T2.Keyfield FROM table2 T2 LEFT OUTER JOIN table1 T1 on T2.Keyfield = T1.Keyfield WHERE T1.Keyfield IS NULL)

Posting Permissions

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