Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择并更新SQL_Sql_Sql Server - Fatal编程技术网

选择并更新SQL

选择并更新SQL,sql,sql-server,Sql,Sql Server,我正在使用下面的查询提取数据,它吸引了大约200个用户 Select users.user_id, users.first_name, users.last_name, user_profiles.role, user_profiles.last_modified, user_profiles.last_modified_by From users Inner Join user_profiles on user_profiles.user_id =

我正在使用下面的查询提取数据,它吸引了大约200个用户

Select 
    users.user_id, users.first_name, users.last_name,
    user_profiles.role, user_profiles.last_modified, 
    user_profiles.last_modified_by
From
    users
Inner Join
    user_profiles on user_profiles.user_id = users.user_id
Where 
    project_id = '28'
    and role like 'customer__bread__fsubmit__fedit__bdefault'
order by 
    last_modified
我现在想将角色更新为以下新角色:

IBS__bGlobal__bCustomer__b__P__bTLO__b__p
如何将该角色合并到select查询中

非常感谢您的帮助。

这里有一种方法

UPDATE up
SET    up.role = 'IBS__bGlobal__bCustomer__b__P__bTLO__b__p'
FROM   users u
       INNER JOIN user_profiles up
               ON up.user_id = u.user_id
WHERE  project_id = '28'
       AND up.role = 'customer__bread__fsubmit__fedit__bdefault' 

另外,当您不需要通配符搜索时,请使用
=
而不是像

(1)限定所有列名,以便读者能够理解您的查询。(2) 用您实际使用的数据库标记您的问题。是否要更新数据库或更改select以使其返回其他数据?@GordonLinoff表为:1。用户和2。用户配置文件。关于正在使用的数据库,我使用的是SQL 2008 r2。非常感谢。