2016-02-27 84 views
1

我正在使用下面的查询提取数据,该数据可以吸引大约200个用户。选择并更新SQL

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 

我如何可以将这个角色到选择查询?

您的协助,将不胜感激。

+3

(1)所有符合条件的列名,以便读者能理解你的查询。 (2)用你实际使用的数据库标记你的问题。 –

+1

是否要更新数据库或更改select以便返回其他数据? –

+0

@GordonLinoff的表格有:1.用户和2. user_profiles。关于我正在使用SQL 2008 R2的数据库。谢谢。 – SqlNovice

回答

1

这里有一种方法

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' 

此外,当您不需要通配符搜索,然后使用=代替Like