更新另一个表时必须声明标量变量@tablename

时间:2018-06-21 19:09:46

标签: sql sql-server set sql-update

我正在尝试:

static int countA = 0;
static int countB = 0;
static pthread_mutex_t lockCountA = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t lockCountB = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t lockA = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t lockB = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t condA = PTHREAD_COND_INITIALIZER;
static pthread_cond_t condB = PTHREAD_COND_INITIALIZER;

// for B(), just s/B/A/g
static void A(void) {
    pthread_mutex_lock(&lockB);
    while(countB)
        pthread_cond_wait(&condB, &lockB);
    pthread_mutex_lock(&lockCountA);
    countA += 1;
    pthread_mutex_unlock(&lockCountA)
    doA();
    pthread_mutex_lock(&lockCountA)
    countA -= 1;
    if countA == 0:
        pthread_cond_signal(&condA);
    mutex_unlock(&lockCountA)
    mutex_unlock(&lockB);
}

但是当我这样做时,我得到了错误:

  

必须声明标量变量“ @declaredTable”

两次。

如何将现有表的值更新为已声明表的值?

为什么不起作用?

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:3)

您需要JOIN

UPDATE e 
      SET e.code = d.code
FROM existingTable e INNER JOIN 
     @declaredTable d
     on d.id = e.id;