SQL在查询字符串中使用列值作为关键字 [英] SQL Use Column Value as Keyword in Query String
本文介绍了SQL在查询字符串中使用列值作为关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
确定,所以这里是示例查询:
Ok so here is the example query:
SELECT DISTINCT id, amount FROM tbl_recurring_payment AS t
WHERE ADDDATE(t.start_date, INTERVAL (t.period) UPPER(t.unit)) = CURDATE());
该区域是UPPER(t.unit),我希望将该expr视为mysql关键字(此列的可能值为日,周,月,年)。它会抛出一个错误,因为它不能使用expr作为关键字。有没有什么可以做的,让这个工作,或者我应该添加一个单位的检查和硬编码单位的每个可能的价值的关键字?
The area in question is UPPER(t.unit) where I want that expr to be treated as a mysql keyword (possible values of this column are day, week, month, year). It throws an error since it cant use the expr as a keyword. Is there anything I can do to get this to work or should I just add a check for the unit and hardcode the keyword for each possible value of unit?
推荐答案
我真的只需要知道它是否可能在查询字符串中使用列值作为关键字
I really just need to know if its possible to use an column value as a keyword in a query string
NO
这篇关于SQL在查询字符串中使用列值作为关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文