Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 每次使用不同的用户ID调用存储过程中的sql函数_Sql Server 2005_Stored Procedures_Sql Function - Fatal编程技术网

Sql server 2005 每次使用不同的用户ID调用存储过程中的sql函数

Sql server 2005 每次使用不同的用户ID调用存储过程中的sql函数,sql-server-2005,stored-procedures,sql-function,Sql Server 2005,Stored Procedures,Sql Function,我有一个sql函数并使用SQLServer2005 dbo.util(@dailyDate,@userId) 现在我想为特定日期的每个@userId调用这个函数 Create PROCEDURE [dbo].[DailyAttendenceTemp] @dailyDate nvarchar(10) WITH EXEC AS CALLER AS Select * FROM dbo.util (@dailyDate,@userId) //I think error is here. WHERE @

我有一个sql函数并使用SQLServer2005

dbo.util(@dailyDate,@userId)

现在我想为特定日期的每个@userId调用这个函数

Create PROCEDURE [dbo].[DailyAttendenceTemp]
 @dailyDate nvarchar(10)
WITH EXEC AS CALLER
AS
Select * FROM dbo.util (@dailyDate,@userId) //I think error is here.
WHERE @userId in (SELECT UserId From TTransactionLog1)
GO
但是当我执行这个过程时,它给出了一个错误-

SQL Server数据库错误:必须声明标量变量“@userId”


因此,请告诉我如何更正该过程,以便我只给出日期作为参数,它对每个@userId运行相同的函数。

我得到了答案,现在我使用While循环,它解决了我的问题

DECLARE @i int
DECLARE @userid nvarchar(10)
DECLARE @numrows int

DECLARE @tempUserId_table TABLE (
    idx smallint Primary Key IDENTITY(1,1)
    , userid nvarchar(10)
)

INSERT @tempUserId_table
SELECT distinct UserID FROM TUser 


-- enumerate the table
SET @i = 1
SET @numrows = (SELECT COUNT(*) FROM @tempUserId_table)
IF @numrows > 0
    WHILE (@i <= (SELECT MAX(idx) FROM @tempUserId_table))
    BEGIN


        -- get the next userId primary key
        SET @userid = (SELECT userid FROM @tempUserId_table WHERE idx = @i)



          Select * FROM dbo.util (@dailyDate,@userid) 


        -- increment counter for next userId
        SET @i = @i + 1
    END
DECLARE@i int
声明@userid nvarchar(10)
声明@numrows int
声明@tempUserId_表(
idx smallint主键标识(1,1)
,userid nvarchar(10)
)
插入@tempUserId_表
从TUser中选择不同的用户ID
--列举表格
设置@i=1
设置@numrows=(从@tempUserId_表中选择COUNT(*)
如果@numrows>0
而(@i