I would like to create a stored procedure in Sql Server that calls one of a number of different stored procedures and chooses which one based on the parameter supplied to it, but I can’t seem to get the choosing syntax right.
Currently attempting:
Begin
Set nocount on;
exec iif(param='individual', sp_FindIndividualRespondents,
iif(param='org', sp_FindOrgRespondents, sp_FindGroupRespondents))
End
This is currently telling me: Incorect syntax near ‘param’.
I have looked here: conditional where clause based on a stored procedure parameter?, but I can’t work out how to change that code to suit my situation.
How do i provide a parameter to a stored procedure and then use it to choose and run a different stored procedure?
If you do not need the dynamic sql, which it appears in this example you do not, you can simply check the value and run the appropriate stored procedures: