开发者

Updating an array of users (having the same username and email)

开发者 https://www.devze.com 2023-03-07 20:57 出处:网络
I\'m maintaining an old ASP application (please don\'t tell me what you think about ASP, I\'m already painfully aware myself) and I\'m tasked to easy\'fy the user administration.

I'm maintaining an old ASP application (please don't tell me what you think about ASP, I'm already painfully aware myself) and I'm tasked to easy'fy the user administration.

The user table looks like this:

userID | companyID | loginname | email | endDate | ...

I built some shorthand functions to set properties for an array of users. Normally the SQL to set, for example, the endDate is simple: update users set end开发者_C百科Date=x where userID in(y)

The problem lies in that the same user can exist multiply times, ie user 'David' is registered as a user for company C1, C2 and C3. A user is considered "the same" if both email and loginname is the same.

Question:

How can I set the same endDate for David, Lisa and Erik (for all companies) at the same time?


Please try this

UPDATE u 
SET endDate=x 
FROM USERS u 
INNER JOIN
(
    SELECT loginname, email FROM USERS  WHERE userID IN (y)
) a
ON u.loginname = a.loginname
AND u.email = a.email
0

精彩评论

暂无评论...
验证码 换一张
取 消