I have a T-SQL stored procedure with the following parameters
CREATE PROCEDURE [dbo].[SaveData]
-- Add the parameters for the stored procedure here
@UserID varchar(50),
@ServiceID varchar(50),
@param1 varchar(50),
@param2 varchar(50),
@endDate datetime
AS BEGIN
.
.
-- my code --
I want know if it is possible to pass a result of select as parameter:
exec SaveDate (SELECT player.UserID,player.ServiceID, 'no','no',GETDATE()
FROM player)
I tried something like this, but it does not work.
The SELECT query you wrote in your example would probably bring back multiple rows (your SELECT does not feature a WHERE clause or a TOP(n)). If your intention is to be able to have your procedure engage a “tabular” set of parameters, from SQL Server 2008, you are able to use table valued parameters.
This involves creating a user defined table table and will almost undoubtedly mean adjusting the logic inside the stored procedure.
Hope this helps 🙂
See http://msdn.microsoft.com/en-us/library/bb510489(SQL.100).aspx
for more information.