我在使用LIKE的数据库查询中遇到问题

问题描述:

请帮助我。我想要的是,我想在Table1中将所有prefixNo插入到ContactNo的table2的prefixNo中。因此,PrefixNo中Table2中的所有NULL将在table1中的prefixNo中更改为3个字符。







Pls help me. what i want is, I want to Insert all the prefixNo in Table1 to prefixNo of table2 base on the ContactNo. So all the NULL in Table2 in PrefixNo will be change into 3 character in prefixNo in table1.



UPDATE  table2 SET  prefixNo = (SELECT prefixNo WHERE Table1 LIKE prefixNo)  WHERE contactno LIKE (SELECT prefixNo WHERE Table1 LIKE prefixNo) ORDER BY prefixNo





它不起作用。我尝试不同类型的编码,但它不起作用。 :(。有什么问题?请帮助我。



table1



It's not working. I try different type of coding but it doesn't work. :(. what is problem? pls help me.

table1

id  |    prefixNo
1   |   910
2   |   922
3   |   920
4   |   929
5   |   930
6   |   932
7   |   933




table2



table2

id  |   prefixNo|   ContactNo
1   |   NULL    |   9309556384
2   |   NULL    |   9307815328
3   |   NULL    |   9334489301
4   |   NULL    |   9330000024
5   |   NULL    |   9108456218
6   |   NULL    |   9305789621
7   |   NULL    |   9335554868
8   |   NULL    |   9224813354
9   |   NULL    |   9222224568
10  |   NULL    |   9105789545





ok。所以这是我要显示的输出



输出:



ok. so this is the output i want to display

OUTPUT:

Table 2
id  |   prefixNo|   ContactNo
1   |   930 |   9309556384
2   |   930 |   9307815328
3   |   933 |   9334489301
4   |   933 |   9330000024
5   |   910 |   9108456218
6   |   930 |   9305789621
7   |   933 |   9335554868
8   |   922 |   9224813354
9   |   922 |   9222224568
10  |   910 |   9105789545

update-row-with-sql-statement-with-like-fails.html [ ^ ]



试试这种方式..希望你能得到它......
update-row-with-sql-statement-with-like-fails.html[^]

Try this way..hope you will get it...


UPDATE  TABLE2  SET
prefixNo=B.prefixNo  FROM TABLE1 B WHERE contactno LIKE B.prefixNo+'%'





这可以获得您想要什么



THIS CAN GET WHAT YOU WANT


试试这个,



Try this,

UPDATE  TABLE2  
SET prefixNo= left(ContactNo, 3)