2016-04-11 70 views
1

我需要构建一个从配置表中检索值的SQL Server 2012查询。代码如下所示:从查询中的配置表中检索值其中子句

Product 
product_types product_description 
001 Milk 
002 Butter 
003 Oatmeal 

Configuration_table

product_nr 
001 
003 

查询:

SELECT * 
FROM product 
WHERE product.types in (select product_nr from configuration_table) 

只有001和003应该显示。但是这个查询没有结果。这怎么可以纠正?

感谢您的回复!

+1

数据类型product.types和Configuration_table.product_nr? – jarlh

+0

嗨jarlh感谢您的回复。 product_types和product_nr是nvarchar数据类型 – mgo

+0

我想用整数代替。 – jarlh

回答

1

您查询似乎不错,但仍然没有工作尝试修剪列,其在使用WHERE条件

SELECT * 
FROM product 
WHERE TRIM(product.types) in (select TRIM(product_nr) from configuration_table) 
+0

现在它的工作!感谢您的帮助jaydipJ – mgo

+0

我怎么能得到更多的积分,所以我可以投你一票。 – mgo

+1

明白了!谢谢 – mgo