SQL code for fin, copy and paste :
Hi i have two tables ...
Helpfull table:
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
And i need create a SQL code which i can find row in table00008 which in the TEXT has data from CISLO from table00006 and copy value in NAME by matching CISLO>TEXT
result:
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
Can anyone help me I have desperately Thx, Martin
In T-SQL you can write a join and update as:
--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'%';
Demo.
Now try this one for your scenario.
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)
I beleive you would have had some relationship to join these two tables. IF so try the below one.
[For the case of CISLO in TABLE 'skladovekarty00006' can be anywhere in TEXT of TABLE 'skladovekarty00008']
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/94224.html
上一篇: 单个服务器上的Mysql复制
下一篇: fin,复制和粘贴的SQL代码: