Double Insert Statement Probs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MATTXtwo
    New Member
    • Sep 2006
    • 83

    Double Insert Statement Probs

    Code:
    ALTER PROCEDURE [dbo].[get_user]
    (	
    	@user_id varchar(8),
    	@pwd varchar(12)
    	)
    AS
    
    IF EXISTS(SELECT Personel_No From TblUser_ID where Personel_No = @user_id)
      BEGIN
      IF EXISTS(SELECT Password From TblUser_ID where Personel_No = @user_id AND Password = @pwd)
               BEGIN
    INSERT INTO TblAudit_Trails(Personel_No,IC_Baru,Business_Area) 
    SELECT Personel_No,IC_Baru,Business_Area 
    From TblPeribadi 
    WHERE Personel_No = @user_id AND IC_Baru = @pwd
    RETURN(3)
               END
      ELSE
               RETURN(1)
      END
    ELSE
      BEGIN
      IF EXISTS(SELECT Personel_No From TblPeribadi where Personel_No = @user_id)
    	BEGIN
    	IF EXISTS(SELECT IC_Baru From TblPeribadi where Personel_No = @user_id AND IC_Baru = @pwd)
    		BEGIN
    		INSERT INTO TblAudit_Trails(Personel_No,IC_Baru,Business_Area) 
    		SELECT Personel_No,IC_Baru,Business_Area 
                    	From TblPeribadi 
    		WHERE Personel_No = @user_id AND IC_Baru = @pwd
    	
                    	INSERT INTO TblUser_ID(Personel_No,Password,Update_By) 
    		VALUES(@user_id,@pwd,@user_id)
    		RETURN(4)
                                    END
    	ELSE
    		RETURN(2)
    	END
      ELSE
                    RETURN(0)
    END
    //Msg 207, Level 16, State 1, Procedure get_user, Line 15
    Invalid column name 'Personel_No'.
    Msg 207, Level 16, State 1, Procedure get_user, Line 30
    Invalid column name 'Personel_No'.

    It appears as my thought cannot be double INSERT statement.but some example of SQL statement that I search for make it successful
    So someone please help me..........
    Last edited by acoder; Sep 24 '08, 01:40 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Moved to the SQL Server forum (I'm guessing slightly - might belong to Oracle). If it's the wrong forum, could a moderator kindly move it to the correct forum.

    @OP, please post your questions in the correct forum. This does not belong in the Feedback forum.

    Moderator.

    Comment

    • iburyak
      Recognized Expert Top Contributor
      • Nov 2006
      • 1016

      #3
      Check if TblUser_ID has a column Personel_No

      It is hard to tell because I don't see your database objects.

      Comment out pieces of your code and run it to find which one is having a problem.

      Good Luck.

      Comment

      • MATTXtwo
        New Member
        • Sep 2006
        • 83

        #4
        Originally posted by iburyak
        Check if TblUser_ID has a column Personel_No

        It is hard to tell because I don't see your database objects.

        Comment out pieces of your code and run it to find which one is having a problem.

        Good Luck.
        Exactly you're right! I have check it it's my database field name probs.....
        Anyway sorry to burst into wrong forum place

        Comment

        Working...