根据条件更新多行的列值

时间:2016-08-29 07:18:50

标签: sql sql-server join sql-update table-valued-parameters

我正在尝试更新多行的列。以下是我的查询

for (var name in regions) {
    // Select the region DOM element
    var regionDOM = document.querySelector('[data-name="' + name + '"]');

    // Get the `data-template` attribute
    var tpl = regionDOM.getAttribute('data-template');

    // Add the region HTML and template to the payload
    payload.append(name, regions[name]);
}

// Set the template value for the payload to that of the last region
// found.
payload.append('template', tpl);

我想要做的是,我想只为那些没有任何有效计划的成员帐户添加免费信用(= NULL)。成员列表位于Bitmap bitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter( matrix)); canvas.drawBitmap(original, 0, 0, paint); return bitmap; 表值参数中,UPDATE [Members] SET [Credits]=[Credits]+@FreeCredits WHERE [ID] IN (SELECT T1.[MemberID] FROM @Members T1 RIGHT JOIN [Members] T2 ON T1.MemberID!=T2.ID WHERE T2.ActivePlan IS NULL) 是表。

查询未按预期工作。它会向所有成员添加信用,即使是@Members不等于[Members]的成员也是如此。请告诉我如何使用一个更新查询来实现此目的。

2 个答案:

答案 0 :(得分:0)

您不应该使用正确的加入。只做内连接。试试这样,

OnFileActivated

答案 1 :(得分:0)

抱歉,打扰你们。在发布我的问题之后突然发现了解决方案。我试着按照简单的查询,它工作:)

string aadInstance = "https://login.microsoftonline.com/{0}";
string tenant = "<your-tenant>.onmicrosoft.com";
string clientId = "<your-clientId>";
string appKey = "<your-application-key>"; // Or Client Secret
string resourceId = "https://graph.microsoft.com/";
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

var authContext = new AuthenticationContext(authority);
var clientCredential = new ClientCredential(clientId, appKey);
var result = await authContext.AcquireTokenAsync(resourceId, clientCredential);
string response;

using (HttpClient client = new HttpClient())
{
    client.BaseAddress = new Uri("https://graph.microsoft.com");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
    client.DefaultRequestHeaders
        .Accept
        .Add(new MediaTypeWithQualityHeaderValue("application/json"));

    var resultApi = await client.GetAsync("/v1.0/users");
    response = await resultApi.Content.ReadAsStringAsync();
}

请查看是否有任何问题。谢谢:))