views:

863

answers:

1

hi guys, Following is a storedprocedure in which iam passing DriverID=0 and DrivarCode =DD1 and DriverName =Ram. While executing control is going to fails.Control is coming to IF ((@DriverName!=NULL) and ((@DriverCode!=NULL)),After that going to fails. DriverName and DriverCode contains values.But still going to fails .What may be the reason for this

Create Procedure InsertUpdateM
(
    @DriverID int,
    @DriverCode varchar(50),
    @DriverName varchar(50),
    @Msg varchar(50) output
)

AS
BEGIN
IF @DriverID=0
    BEGIN
     SELECT DriverName,DriverCode FROM DriverM WHERE DriverName=@DriverName and DriverCode=@DriverCode
     IF(@@RowCount>0) GOTO Fails
      IF ((@DriverName!=NULL) and ((@DriverCode!=NULL))
       BEGIN
        INSERT INTO DriverM(DriverCode,DriverName) values(@DriverCode,@DriverName)
       END
    END
ELSE
    BEGIN
     SELECT DriverName,DriverCode FROM DriverM WHERE DriverName=@DriverName and DriverCode=@DriverCode
     IF(@@RowCount>0) GOTO Fails
      IF ((@DriverName!=NULL) and ((@DriverCode!=NULL)
       BEGIN
        UPDATE DriverM SET DriverCode=@DriverCode,DriverName=@DriverName WHERE DriverID=@DriverID
       END
    END
END

Fails
    SET @Msg='Failed'
+1  A: 

I'm not even sure how this code parses. You have "Fails" after the end of the stored procedure, and it doesn't end with a colon. You want something more like this:

ELSE
    BEGIN -- Begin 1
     SELECT DriverName,DriverCode FROM DriverM WHERE DriverName=@DriverName and DriverCode=@DriverCode
     IF(@@RowCount>0) GOTO Fails
      IF ((@DriverName!=NULL) and ((@DriverCode!=NULL)
       BEGIN -- Begin 2
        UPDATE DriverM SET DriverCode=@DriverCode,DriverName=@DriverName WHERE DriverID=@DriverID
       END  -- End of 2
    END -- End of 1

GOTO Succeeds
Fails:
    SET @Msg='Failed'
Succeeds:
END -- End of SP
John Saunders