[英]If value in Field1 is null, return value from Field2, otherwise Return String
Although this seems simple enough, I cannot get it, nor was I able to find what I needed via searching on here. 尽管这看起来很简单,但我无法理解,也无法通过在此处搜索找到所需的内容。 I need this to be done within the builder, or within my SQL code which is already an extremely lengthy bit of code for what the query is doing already.
我需要在构建器中或在我的SQL代码中完成此操作,对于已经在执行的查询,这已经是非常冗长的代码。 Here is the basis of the issue:
这是问题的基础:
Fields: ItemID
| 字段:
ItemID
| CustomID
If there is a value in CustomID
, I'd like to overwrite the ItemID
value for that record with a string: "CK"+CustomID
. 如果
CustomID
有一个值,我想用字符串"CK"+CustomID
覆盖该记录的ItemID
值。
If the CustomID
field is empty for that record, then keep the original ItemID
. 如果该记录的
CustomID
字段为空,则保留原始ItemID
。
I then also need the value for that field to be used to pull the correct data from a linked table. 然后,我还需要该字段的值,以用于从链接表中提取正确的数据。 Currently, it will pull the original
ItemID
's values for subsequent fields, rather than the string "CK+CustomID"
value that would be substituted in place of ItemID
. 当前,它将为后续字段提取原始
ItemID
的值,而不是将替换ItemID
的字符串"CK+CustomID"
值。
I thought perhaps an independent subquery would be necessary to discern what the field's value would be, before needing to use that value to gather the subsequent fields from the lookup table. 我认为也许需要一个独立的子查询来识别该字段的值,然后才需要使用该值从查找表中收集后续字段。
I am willing to work with the SQL code generated by my query builder, but I am not the greatest with just the code. 我愿意使用查询生成器生成的SQL代码,但我并不是仅凭代码就可以做到最好。
Thank you for your help! 谢谢您的帮助!
Without seeing a sample of the content of your table or linked table, nor knowing the names of either of these tables, I would suggest the following example code: 在没有看到表或链接表内容的样本,也不知道这些表中任何一个表的名称的情况下,我建议使用以下示例代码:
select *
from yourlinkedtable t inner join
(
select iif(t.customid is null, t.itemid, 'CK' & t.customid) as id
from yourtable t
) q
on t.itemid = q.id
Here, yourtable
represents the table containing the ItemID
and CustomID
fields, and yourlinkedtable
represents the table with which your are looking to match the prefixed ItemID
. 在这里,
yourtable
代表包含ItemID
和CustomID
字段的表,并且yourlinkedtable
代表要与之匹配的前缀ItemID
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.