[英]Select all columns from one table and one from another where column equals variable
Sorry for the long title. 抱歉,标题太长了。
I have a statement which needs to grab all the columns from one row from BinConfig: 我有一条语句需要从BinConfig的一行中获取所有列:
SELECT *
FROM BinConfig WITH(NOLOCK)
WHERE IssuerKey = @IssuerKey
But I also need to grab a single column from one row from CardRangeGroup
also based on that IssuerKey
column. 但是我还需要根据该
IssuerKey
列从CardRangeGroup
一行中获取一列。
What I've tried: 我尝试过的
SELECT
BinConfig.*, CardRangeGroup.Name
FROM
BinConfig
JOIN
CardRangeGroup WITH(NOLOCK)
WHERE
@IssuerKey = BinConfig.IssuerKey
AND @IssuerKey = CardRangeGroup.IssuerKey
Which gives me a syntax error near WHERE
. 这给了我
WHERE
附近的语法错误。 I've tried to find resources online, but everywhere I look I can't find anything explaining how to select rows based on a passed in variable. 我尝试过在线查找资源,但是到处都找不到任何解释如何根据传入变量选择行的内容。 Any help?
有什么帮助吗?
You need to specify how the tables should be joined. 您需要指定如何连接表。 Try this:
尝试这个:
SELECT BinConfig.*, CardRangeGroup.Name
FROM BinConfig
JOIN CardRangeGroup ON BinConfig.IssuerKey = CardRangeGroup.IssuerKey
WHERE @IssuerKey = CardRangeGroup.IssuerKey
The with(nolock)
might not be needed (or a good idea) so I removed it. 可能不需要
with(nolock)
(或一个好主意),所以我删除了它。
try this , you don't need to use where
试试这个,你不需要在
where
使用
SELECT BinConfig.*, CardRangeGroup.Name FROM BinConfig JOIN
CardRangeGroup
ON CardRangeGroup.IssuerKey = BinConfig.IssuerKey AND @IssuerKey = CardRangeGroup.IssuerKey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.