Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure

Author  Topic 

dbjnj5
Starting Member

1 Post

Posted - 2007-10-04 : 16:20:18
I am trying to write my first stored procedure and am trying to follow the flow of another stored procedure. This is the procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[RepairOrderImport] AS

UPDATE RepairOrders

SET uniqueID = P.UniqueID, UnitNumber = P.UnitNumber, SN = P.SN, DateComplete = P.DateComplete, RepairOrderNum = P.RepairOrderNum,
ActualCost = P.ActualCost, Comment2 = P.Comment2, Comments = P.Comments

FROM DMSERVER01.tmvpMccandless.dbo.RepairOrderImport AS P
JOIN RepairOrders ON SN = P.SN
WHERE RepairOrderImport.uniqueID = P.uniqueID

INSERT INTO RepairOrders (uniqueID, UnitNumber, SN, DateComplete, RepairOrderNum, ActualCost, Comment2, Comments, RepairType)

SELECT P.uniqueID ,P.UnitNumber, P.SN, P.DateComplete, P.RepairOrderNum, P.ActualCost, P.Comment2, P.Comments


FROM DMSERVER01.tmvpMccandless.dbo.RepairOrderImport AS P
LEFT JOIN RepairOrders ON uniqueID = P.uniqueID


This is the error I get when I run it

Msg 107, Level 16, State 3, Procedure RepairOrderImport, Line 8
The column prefix 'RepairOrderImport' does not match with a table name or alias name used in the query.
Msg 209, Level 16, State 1, Procedure RepairOrderImport, Line 17
Ambiguous column name 'uniqueId'.

I know I have a long way to go, but would appreciate any help.

Thanks,

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-10-04 : 18:08:56
Try this:

UPDATE RepairOrders

SET uniqueID = P.UniqueID, UnitNumber = P.UnitNumber, SN = P.SN, DateComplete = P.DateComplete, RepairOrderNum = P.RepairOrderNum,
ActualCost = P.ActualCost, Comment2 = P.Comment2, Comments = P.Comments

FROM DMSERVER01.tmvpMccandless.dbo.RepairOrderImport AS P
JOIN RepairOrders R ON R.SN = P.SN
JOIN RepairOrderImport O ON O.uniqueID = P.uniqueID
Go to Top of Page
   

- Advertisement -