Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 通过将表中的不同字段与另一个表中的字段进行匹配,在字段中查找值_Sql_Sql Server_Tsql - Fatal编程技术网

Sql 通过将表中的不同字段与另一个表中的字段进行匹配,在字段中查找值

Sql 通过将表中的不同字段与另一个表中的字段进行匹配,在字段中查找值,sql,sql-server,tsql,Sql,Sql Server,Tsql,我正在尝试做一些非常简单的事情,但是遇到了很多麻烦。 我有两个表,其中一个表由以下字段构成 member.tx_nickname var(100) member.accountnumber int memtransactions.accountnumber (FK uniqueidentifier) 我要做的是查找成员表,并在成员表中找到member.accountnumber=memtransactions.accountnumber的记录的昵称 我已经尝试了一些,但由于字段类型冲突而不断

我正在尝试做一些非常简单的事情,但是遇到了很多麻烦。 我有两个表,其中一个表由以下字段构成

member.tx_nickname var(100)
member.accountnumber int

memtransactions.accountnumber (FK uniqueidentifier)
我要做的是查找成员表,并在成员表中找到member.accountnumber=memtransactions.accountnumber的记录的昵称

我已经尝试了一些,但由于字段类型冲突而不断出现错误

谢谢

试试这个:

SELECT member.tx_nickname
FROM member m
JOIN memtransactions mt ON m.accountnumber = mt.accountnumber

ty bobs但我得到以下错误操作数类型冲突:uniqueidentifier与不兼容int@IanRobson,我以前没有注意到accountnumber的数据类型在每个表中都是不同的。这就是查询失败的原因。这是故意不同的吗?只是我们需要memtransactions中的字段是唯一标识符,它只是成员数据库中的一个普通整数。我认为唯一标识符是一个整数,但显然不是。这是正确的。uniqueidentifier不是整数。您可能希望查看IDENTITY列属性以帮助自动生成唯一的整数值。我会尝试一下,然后再与您联系