I have an SQL stored procedure with several parameters, and I want to call it using several columns from (the same) row for some of the parameters. Here's what the current implementation looks like (not including the unused columns / parameters, which exist):
DECLARE @id int;
select @id = min( id ) from Table_1;
declare @param1 nvarchar(10), @param2 nvarchar(10);
select @param1 = param1, @param2 = param2 from Table_1 WHERE id=@id;
EXEC [dbo].otherProc @param1, @param2;
This is an improvement over multiple selects, but I can't help wondering if there's a way of doing this without variables (except @id). Selecting directly in the EXEC statement doesn't seem to work (or maybe I don't know the right syntax for it).
@idparameter and perform your selects inside the procedure along with your other code.Oracle allows for aRowTypewhich lets you specify a single variable/parameter as a row of a particular table, but afaik, SQL Server does not have this.