如何仅从sqlserver中选择真值
如何从sqlserver中仅选择真值?我编写了一个查询,但当我在sqlserver中测试这个查询时,它返回所有字段,但不是真字段如何仅从sqlserver中选择真值,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,如何从sqlserver中仅选择真值?我编写了一个查询,但当我在sqlserver中测试这个查询时,它返回所有字段,但不是真字段 SELECT Fruit,Drink,Desert,MainFood,Salad,TableFlower,SaloonLighting, Saloondesign,SloonCrew,Pastry,GiftCard FROM WeedingSalonGeneralRes WHERE Fruit='True' and Drink='True'and Desert='
SELECT Fruit,Drink,Desert,MainFood,Salad,TableFlower,SaloonLighting,
Saloondesign,SloonCrew,Pastry,GiftCard
FROM WeedingSalonGeneralRes
WHERE Fruit='True' and Drink='True'and Desert='True'and MainFood='True'and
Salad='True'and TableFlower='True'and SaloonLighting='True'and
Saloondesign='True'and SloonCrew='True'and Pastry='True' and GiftCard='True'
如果字段类型为BIT,则可以执行以下操作:
SELECT Fruit,Drink,Desert,MainFood,Salad,TableFlower,SaloonLighting,
Saloondesign,SloonCrew,Pastry,GiftCard
FROM WeedingSalonGeneralRes
WHERE Fruit=1 and Drink=1 and Desert=1 and MainFood=1 and
Salad=1 and TableFlower=1 and SaloonLighting=1 and
Saloondesign=1 and SloonCrew=1 and Pastry=1 and GiftCard=1
您还可以在输出中解释您想要什么吗?在同一行,您不能
但你可以做到:
with distinctvalueyes (typearticle) as (
select top 1 'Fruit' FROM WeedingSalonGeneralRes where Fruit=1
union all
select top 1 'Drink' FROM WeedingSalonGeneralRes where Drink=1
union all
select top 1 'Desert' FROM WeedingSalonGeneralRes where Desert=1
union all
select top 1 'MainFood' FROM WeedingSalonGeneralRes where MainFood=1
union all
select top 1 'Salad' FROM WeedingSalonGeneralRes where Salad=1
union all
select top 1 'TableFlower' FROM WeedingSalonGeneralRes where TableFlower=1
union all
select top 1 'SaloonLighting' FROM WeedingSalonGeneralRes where SaloonLighting=1
union all
select top 1 'Saloondesign' FROM WeedingSalonGeneralRes where Saloondesign=1
union all
select top 1 'SloonCrew' FROM WeedingSalonGeneralRes where SloonCrew=1
union all
select top 1 'Pastry' FROM WeedingSalonGeneralRes where Pastry=1
union all
select top 1 'GiftCard' FROM WeedingSalonGeneralRes where GiftCard=1
)
select * from distinctvalueyes
你应该提供更多信息,至少澄清“真实价值”的含义。看见如果您发布一些测试数据并解释预期结果,它可能会很有用。否则很难了解实际问题是什么。我想显示只包含真(1)值的字段。但是这个Select查询会显示所有字段。