嗨我有两张桌子......
有用的表格:
SELECT * FROM 36496839_radioamater.skladovekarty00006;
CISLO NAME
WO01 one
WO02 four
WO03 tree (other cells)
Acctive table
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中有来自table00006的CISLO数据,并通过匹配CISLO> TEXT
来复制NAME中的值结果:
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
答案 0 :(得分:1)
在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'%';
答案 1 :(得分:0)
现在尝试一下这个场景。
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)
我相信你会加入这两张桌子。如果是这样尝试下面的 [对于表格中的CISLO案例' skladovekarty00006'可以在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