0

我有这个名为 SubscriptionCharity 的表,它如下所示:

SubscriptionId       ChannelURI       CharUserID
1                       AX                12
2                       ZA                7
3                       AX                10

如果表中的任何记录具有相同的通道 uri 并将其设置为 null ,我想检查特定的 CharUserId ,因此在此表中“Subcriptionid =1”应设置为 null

我对此有两个查询,一个在 MS SQL 管理 m 中有效,但不适用于 LINQ:(它不影响行)

UPDATE SubscriptionCharProg 
Set ChannelURI = null 
FROM SubscriptionCharProg as t1
INNER JOIN SubscriptionCharProg as t2 
    on t1.ChannelURI = t2.ChannelURI 
    and t1.DeviceId = t2.DeviceId 
WHERE CharUserId! = 5

另一个适用于 LINQ 但不适用于 MS SQL 管理:(MS SQL 管理错误:无效的对象名称“t1”)

context.ExecuteStoreCommand("UPDATE t1 Set t1.ChannelURI = 1 FROM SubscriptionCharProg as t1 INNER JOIN  
  SubscriptionCharProg as t2 on t1.ChannelURI = t2.ChannelURI WHERE t1.CharUserId! = " 
  + charuserID + "", null);

另外,主要问题是,两个查询都使每个channelURi都为空,无论它是否相等。

请问有什么想法吗?

编辑:如果具有特定 charuserID 的记录存在两次或更多次,它会保留并且不会将其设置为 null

4

3 回答 3

0

尝试这个:

UPDATE t1
SET ChannelURI = null 
FROM SubscriptionCharProg as t1
INNER JOIN SubscriptionCharProg as t2 
    on t1.ChannelURI = t2.ChannelURI 
    and t1.DeviceId = t2.DeviceId 
    and t1.CharUserID <> t2.CharUserID
WHERE t2.CharUserID = 5
于 2012-06-21T00:41:01.397 回答
0

将第一行从:

UPDATE SubscriptionCharProg 

UPDATE t1
于 2012-06-20T19:39:19.093 回答
0
update quiz_subgroup as sg  

inner join (select qq_qsg_id, count(qq_id) as cnt_ques from quiz_questions group by qq_qsg_id) as ques on(ques.qq_qsg_id = sg.qsg_id) 

set sg.qsg_count_of_questions = ques.cnt_ques;
于 2013-10-01T07:04:56.467 回答