Connecting Tech Pros Worldwide Forums | Help | Site Map

Double Insert Statement Probs

Member
 
Join Date: Sep 2006
Posts: 73
#1: Sep 24 '08
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[get_user]
  2. (    
  3.     @user_id varchar(8),
  4.     @pwd varchar(12)
  5.     )
  6. AS
  7.  
  8. IF EXISTS(SELECT Personel_No From TblUser_ID where Personel_No = @user_id)
  9.   BEGIN
  10.   IF EXISTS(SELECT Password From TblUser_ID where Personel_No = @user_id AND Password = @pwd)
  11.            BEGIN
  12. INSERT INTO TblAudit_Trails(Personel_No,IC_Baru,Business_Area) 
  13. SELECT Personel_No,IC_Baru,Business_Area 
  14. From TblPeribadi 
  15. WHERE Personel_No = @user_id AND IC_Baru = @pwd
  16. RETURN(3)
  17.            END
  18.   ELSE
  19.            RETURN(1)
  20.   END
  21. ELSE
  22.   BEGIN
  23.   IF EXISTS(SELECT Personel_No From TblPeribadi where Personel_No = @user_id)
  24.     BEGIN
  25.     IF EXISTS(SELECT IC_Baru From TblPeribadi where Personel_No = @user_id AND IC_Baru = @pwd)
  26.         BEGIN
  27.         INSERT INTO TblAudit_Trails(Personel_No,IC_Baru,Business_Area) 
  28.         SELECT Personel_No,IC_Baru,Business_Area 
  29.                     From TblPeribadi 
  30.         WHERE Personel_No = @user_id AND IC_Baru = @pwd
  31.  
  32.                     INSERT INTO TblUser_ID(Personel_No,Password,Update_By) 
  33.         VALUES(@user_id,@pwd,@user_id)
  34.         RETURN(4)
  35.                                 END
  36.     ELSE
  37.         RETURN(2)
  38.     END
  39.   ELSE
  40.                 RETURN(0)
  41. END
  42.  
//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..........

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 24 '08

re: Double Insert Statement Probs


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.
iburyak's Avatar
Expert
 
Join Date: Nov 2006
Posts: 1,017
#3: Sep 24 '08

re: Double Insert Statement Probs


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.
Member
 
Join Date: Sep 2006
Posts: 73
#4: Sep 25 '08

re: Double Insert Statement Probs


Quote:

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
Reply