fin,复制和粘贴的SQL代码:

嗨,我有两张桌子...

有用表格:

SELECT * FROM 36496839_radioamater.skladovekarty00006;

CISLO    NAME
WO01       one
WO02       four
WO03       tree                  (other cells)

活动表

SELECT * FROM 36496839_radioamater.skladovekarty00008;

TEXT                                          NAME
Osvetlenie LED SMARTBAR 3x1,7W WW > WO01        NULL
Osvetlenie LED SMARTBAR 2x1,7W WW > WO02        NULL
Osvetlenie LED SMARTBAR 2x1,7W WW - WO03        NULL                  (other cells)
Osvetlenie LED SMARTBAR 2x1,7W WW / WO04        NULL
Osvetlenie LED SMARTBAR 2x1,7W WW + WO05        NULL

我需要创建一个SQL代码,我可以在table00008这在TEXT从CISLO从table00006有数据发现行通过匹配CISLO>文本名称复制值

结果:

TEXT                                          NAME
Osvetlenie LED SMARTBAR 3x1,7W WW WO01        one
Osvetlenie LED SMARTBAR 2x1,7W WW WO02        four
Osvetlenie LED SMARTBAR 2x1,7W WW WO03        tree                  (other cells)
Osvetlenie LED SMARTBAR 2x1,7W WW WO04        NULL
Osvetlenie LED SMARTBAR 2x1,7W WW WO05        NULL

任何人都可以帮助我,我绝望地Thx,Martin


在T-SQL中,您可以编写联接并更新为:

--First check if you get desired results:
Select T1.Text ,T2.CISLO ,T2.Name 
FROM @skladovekarty00008 as T1 
join @skladovekarty00006 as T2 on T1.Text like  N'%' + T2.CISLO + N'%';


--If T2.Name are the values with which you want to replace T1.Name then write as
Update T1
Set T1.Name = T2.Name 
FROM @skladovekarty00008 as T1 
join @skladovekarty00006 as T2 on T1.Text like  N'%' + T2.CISLO + N'%';

演示。


现在尝试一下你的场景。

UPDATE b  
SET b.NAME = a.NAME  
FROM  
36496839_radioamater.skladovekarty00006 a   
join  
36496839_radioamater.skladovekarty00008 b  
ON a.CISLO = SUBSTRING(REVERSE(b.TEXT),0,CHARINDEX(' ',REVERSE(b.TEXT))-1)   

我相信你会有一些关系来加入这两张表。 如果是这样,请尝试下面的。
[对于TABLE'skladovekarty00006'中的CISLO的情况可以在TABLE'skladovekarty00008'的TEXT中的任何位置]

UPDATE b  
 SET b.NAME = CASE WHEN PATINDEX('%a.CISLO%',b.TEXT) > 0 THEN a.NAME END  
 FROM  
 36496839_radioamater.skladovekarty00006 a  
 join  
 36496839_radioamater.skladovekarty00008 b  
ON a.keycol = b.keycol  
链接地址: http://www.djcxy.com/p/94223.html

上一篇: SQL code for fin, copy and paste :

下一篇: How to select rows with no matching entry in another table?