0

How can I use function while passing parameters?

for example, want to use LEFT() function while passing parameter value to my stored procedure

like below:

Doesn't work when use any function directly as below:

EXEC [dbo].[MyStoredProcedure] @MyStringParameter = LEFT('ABCDEF',3);

Works if use variable as below:

DECLARE @MyStr VARCHAR(3)=LEFT('ABCDEF',3);
EXEC [dbo].[MyStoredProcedure] @MyStringParameter = @MyStr;

In my case, I have list of parameters and don't want to declare every single variable one by one. kindly tell me if any way to use functions/udf instead declare variable.

Haseeb
  • 746
  • 7
  • 22
  • Using an equals sign is not the same as passing parameters...Or have I missed something? Post your SP code perhaps – Grantly Mar 06 '20 at 22:32
  • 2
    You can only pass constants or variables as parameters, not expressions. – Thom A Mar 06 '20 at 22:33
  • @Grantly thanks for suggest, the sample code is mentioned in question. actual code will not help here. – Haseeb Mar 07 '20 at 10:06

0 Answers0