0

这就是我所拥有的,我想做的是在我的选择中使用 [Value]。我不确定在 select 语句中到底要使用什么!谢谢!

DECLARE
TCursor CURSOR FOR
  SELECT [Value] FROM [dbo].[SPLIT] (';', @SplitVar);
OPEN TCursor ;
FETCH NEXT FROM TCursor ;

WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @ETo =
         (SELECT Email
            FROM mytable
           WHERE user= TCursor );
  EXEC sp_SendAn

我不确定这部分SELECT Email FROM mytable WHERE user= TCursor

4

1 回答 1

0

将光标值提取到变量中:

DECLARE @curvar VARCHAR(50)
DECLARE
TCursor CURSOR FOR
  SELECT [Value] FROM [dbo].[SPLIT] (';', @SplitVar);
OPEN TCursor ;
FETCH NEXT FROM TCursor INTO @curvar;

WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @ETo =
         (SELECT Email
            FROM mytable
           WHERE user= @curvar );
  EXEC sp_SendAn

不确定您打算做什么@Eto,您可能必须使用:

  SET @ETo = '
         (SELECT Email
            FROM mytable
           WHERE user= '+@curvar+' )'
  EXEC sp_SendAn
于 2013-08-14T20:38:00.107 回答