根据字段内容仅更改一行上的选择的 WHERE
好吧,这可能听起来有点奇怪,但我需要做的很简单。 我有一份公司列表,每个公司都有一个描述。 该网站有 4 种语言版本。 当我用英语列出一家公司但负责用法语翻译的人仍然没有进行翻译时,我的问题就出现了,所以我有一个简单的:
SELECT TOP(6)
company.name,
company.description,
company.address
WHERE
langid=1
ORDER BY
company.id DESC
真正的查询更复杂,但我认为它会有了这个就更容易理解这个问题了。 我需要做的是,当 langid 2 中的描述为空时,请显示 langid 1,因为 langid 1 始终是第一个添加的描述。 我不想将描述字段显示为空。
想象一下,第 1 行、第 2 行、第 3 行和第 5 行有 langid 2 的描述,但没有第 4 行和第 6 行。我需要为包含它的行显示 langid 2,但为没有描述的行显示 langid 1。
我知道我可能可以用 @i 字段递增并将结果一一插入到临时表中,但是有没有更好的方法呢?
Ok, this may sound a little weird, but what I need to do is simple. I have a list of companies and each one has a description. The site is in 4 languages. My problem comes when I have listed a company in English but the person who is in charge of translating it in French still didn't make the translation, so I have a simple:
SELECT TOP(6)
company.name,
company.description,
company.address
WHERE
langid=1
ORDER BY
company.id DESC
The real query is more complex, but I think it will be easier with this one to understand the problem. What I need to do is, when the description is empty in langid 2 then show me the langid 1 as langid 1 is always the first one that will be added. I don't want to show the description field empty.
Imagine row 1, row 2, row 3 and row 5 have a description for langid 2 but not row 4 and row 6. I need to show langid 2 for the rows containing it but langid 1 for the rows with no description.
I know that I could probably do a while with a @i field incrementing and inserting the results one by one in a temp table, but is there any better way of doing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非缺少
lng1.name
等(即英语/后备变体),否则这将起作用。如果仅缺少部分本地化变体,它也不会用英语/后备版本替换整个地址。 仅替换缺失的部分。
This will work unless there is
lng1.name
etc. (i.e. the English language/fallback variant) missing.It will also not replace the entire address with the English/fallback version if only part of the localized variant is missing. Only the missing parts will be substituted.