我在使用LIKE的数据库查询中遇到问题 [英] i have a problem in my query in database using LIKE

查看:88
本文介绍了我在使用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

< br $>


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 [< a href =http://ask.sqlservercentral.com/questions/19796/update-row-with-sql-statement-with-like-fails.html\"target =_ blanktitle =New Window> ^ ]



试试这种方式..希望你能得到它......
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)


这篇关于我在使用LIKE的数据库查询中遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆