0

I have stored procedure like this,

Create Procedure [dbo].[Get_Data](
@Id as Varchar(20),
@Type as Varchar(10)
)
As
Begin
  IF(@Type = 'skill')
  Begin 
   .....
   select * ....
  END

  IF(@Type = 'agent')
  Begin 
   .....
   select * ....
  END

  IF(@Type = 'skillProfile') 
  Begin 
    Print 'abc'
    select * ....
   .....
  END
END

Note: there is no syntax or any other error inside any of the if loops as every select query inside each loops are tested successfully.

So now, When i try to execute procedure using command as below,

EXEC  [Get_Data] '1391520','skillProfile'

the statement print is not printed also dint get any rows in return, instead i get message Commands completed successfully.

I tried changing last(i.e. here third) if loop statement i.e. from IF(@Type = 'skillProfile') to IF(@Type = 'profile') and tried executing like EXEC [Get_Data] '1391520','profile' which worked all fine!

Got confused with this and tried changing first if loop and last(third) if loop like this, IF(@Type = 'skill') to IF(@Type = 'xyz') and IF(@Type = 'skillProfile') to IF(@Type = 'xyzProfile') and tried executing like EXEC [Get_Data] '1391520','xyzProfile' which also worked all fine.

Now i am totally confused why it doesn't work when i use skill and skillProfile.

2 Answers 2

3

You defined your parameter as Varchar(10), which means it cannot hold more than 10 characters. If you try to assign it a longer value, it gets truncated with no warning. So you are trying to execute your procedure with @Type='skillProfi'. The solution is to increase the size of your parameter, say varchar(100).

Sign up to request clarification or add additional context in comments.

1 Comment

oh shit! yes you are right, i dint notice that. thanks a lot.
0

Use Try catch block you will let know where error is

Create Procedure [dbo].[Get_Data](
@Id as Varchar(20),
@Type as Varchar(10)
)
As
BEGIN TRY
    SET NOCOUNT ON
  IF(@Type = 'skill')
  Begin 
   .....
   select * ....
  END

  IF(@Type = 'agent')
  Begin 
   .....
   select * ....
  END

  IF(@Type = 'skillProfile') 
  Begin 
    Print 'abc'
    select * ....
   .....
 END TRY

BEGIN CATCH
    SELECT ERROR_NUMBER() AS ErrorNumber
     ,ERROR_SEVERITY() AS ErrorSeverity
     ,ERROR_STATE() AS ErrorState
     ,ERROR_PROCEDURE() AS ErrorProcedure
     ,ERROR_LINE() AS ErrorLine
     ,ERROR_MESSAGE() AS ErrorMessage;
END CATCH

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.