Need help writing a stored procedure

  • I am fairly new to SQL Server. I am trying to write a stored procedure to update fields in a table with information in another table. Both tables have a common key field. I have not been able to get this to work. Any help would be graetly appreciated.

    Percival Bragg


    Percival Bragg

  • Hi Percival,

    If you post what you have, we'll try to help. What you're trying to do is pretty straight forward I think, something like this:

    Create proc usp_DoSomething as

    --Sample proc to update a table

    set nocount on

    update a set a.somefield=b.somefield from table1 as A inner join table2 as B on A.primarykey=b.primarykey where b.someotherfield='whocares'

    Andy

  • My suggestion is to try to accomplish your goal in query analyzer first. Once you have the sql working copy it into a stored procedure.

  • Post your code and we can help, but Leon is right. Get it working in QA first.

    Steve Jones

    steve@dkranch.net

  • Thanks everyone for your help. I was able to accomplish what I wanted using your suggestions. Your help was well appreciated.

    Percival Bragg


    Percival Bragg

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply