Sql 如果状态等于true,则更改为;“uitgeleend”;
我试图从状态可以为true或false的表中查询项目 如果状态为true,我希望将值更改为“uitgeleen”(借出,荷兰语)。另外,如果状态为false,我希望返回的值为“Binnen”(库存,荷兰语) 不知道如何查询这样的问题。我不知道 差不多 还是我现在正在做一些非常愚蠢的事情 编辑:这是我的原始查询,必须添加状态:Sql 如果状态等于true,则更改为;“uitgeleend”;,sql,Sql,我试图从状态可以为true或false的表中查询项目 如果状态为true,我希望将值更改为“uitgeleen”(借出,荷兰语)。另外,如果状态为false,我希望返回的值为“Binnen”(库存,荷兰语) 不知道如何查询这样的问题。我不知道 差不多 还是我现在正在做一些非常愚蠢的事情 编辑:这是我的原始查询,必须添加状态: SELECT Item.Titel, Item.Uitgever, Game.PEGI, Game.EAN, convert(varchar, Item.DvU, 101
SELECT Item.Titel, Item.Uitgever, Game.PEGI, Game.EAN, convert(varchar, Item.DvU, 101) AS DatumVUitgave, Platform.Soort as Platform, Media.soort as Media, GameGenre.Genre AS Genre FROM Game LEFT JOIN ITEM ON Item.ID = Game.itemID LEFT JOIN Media ON Game.MediaID = Media.Id LEFT JOIN Platform ON Game.PlatformID = Platform.Id LEFT JOIN GameGenre ON Game.GameGenreID = GameGenre.Id
您可以使用
case
进行此操作
假设您谈论的是位
列,请执行以下操作:
SELECT
Item.Titel, Item.Uitgever, Game.PEGI, Game.EAN,
convert(varchar, Item.DvU, 101) AS DatumVUitgave,
Platform.Soort as Platform, Media.soort as Media,
GameGenre.Genre AS Genre,
-- here's your new column:
case when Item.Status=1 then 'Uitgeleend' else 'Binnen' end as Status
FROM Game
LEFT JOIN ITEM ON Item.ID = Game.itemID
LEFT JOIN Media ON Game.MediaID = Media.Id
LEFT JOIN Platform ON Game.PlatformID = Platform.Id
LEFT JOIN GameGenre ON Game.GameGenreID = GameGenre.Id
如果它是一个实际的字符串“true”,那么只需将1
更改为'true'
convert
用于更改列的类型-例如,将数字转换为文本,或将文本转换为日期时间。我应该提到,我还在查询中添加了其他内容。我应该把你刚写的部分放在哪里?它起作用了!我在添加行时忘记了逗号。非常感谢!
SELECT
Item.Titel, Item.Uitgever, Game.PEGI, Game.EAN,
convert(varchar, Item.DvU, 101) AS DatumVUitgave,
Platform.Soort as Platform, Media.soort as Media,
GameGenre.Genre AS Genre,
-- here's your new column:
case when Item.Status=1 then 'Uitgeleend' else 'Binnen' end as Status
FROM Game
LEFT JOIN ITEM ON Item.ID = Game.itemID
LEFT JOIN Media ON Game.MediaID = Media.Id
LEFT JOIN Platform ON Game.PlatformID = Platform.Id
LEFT JOIN GameGenre ON Game.GameGenreID = GameGenre.Id