读书人

!SQL写法有关问题把筛选的结果一次

发布时间: 2012-06-09 17:16:42 作者: rapoo

求助!SQL写法问题,把筛选的结果一次性修改
在TF_BOM表, PRD_NO这个字段:

字段 PRD_NO
---------------------
abc
abcR
cde
cdeR
def
defR
---------------------

下面语句是我筛选出结果的SQL:
----------------------------------
select distinct PRD_NO from TF_BOM where PRD_NO in(select left(PRD_NO,len(PRD_NO) -1) from TF_BOM where right(PRD_NO,1) ='R')

我想把结果一次性修改成带R的,求教怎么写SQL,可以用多行代码(只要能在查询器里执行就可以)

[解决办法]

SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([PRD_NO] varchar(4))insert [test]select 'abc' union allselect 'abcR' union allselect 'cde' union allselect 'cdeR' union allselect 'tyt' union allselect 'tytR' union allselect 'gfh' union allselect 'fgg' union allselect 'def' union allselect 'defR'update test  set [PRD_NO]=[PRD_NO]+'R' where exists(select 1 from test b where test.PRD_NO=left(b.PRD_NO,LEN(b.PRD_NO)-1))select * from test/*PRD_NO-----------abcRabcRcdeRcdeRtytRtytRgfhfggdefRdefR*/--你看看这个结果对不? 

读书人网 >SQL Server

热点推荐