英文:
Search result that has a C and a number after the C in the Part Number Field in ColdFusion
问题
在CFQuery的Where语句中,您可以使用以下条件来筛选以'C'后跟数字的零件号:
Where Part_Number Like 'C[0-9]%'
这将只显示类似于'C4560'的零件号,而不会显示像'CBT-BGA'这样的零件号。希望这对您有所帮助。
英文:
I have a search results page that lists part numbers that engineers have to work on, but I only want part numbers displayed on the results page that have a C and then a number after the C in the part number. This is done in ColdFusion. How do I write this in the Where statement in my CFQuery? If I write Where Part_Number Like 'C%', it lists all the parts that have anything after a C in the part number like CBT-BGA. I want it to find only part numbers like this: C4560. I also tried this: Where Part_Number Like '^C[0-9]', but this doesn't show any results. Thanks for your help.
答案1
得分: 0
我们需要知道您使用的数据库类型,以便为您提供正确的答案。您使用ColdFusion并不影响您需要生成的SQL结构。
如果您使用的是SQL Server,SQLShack建议您可以使用like
操作符进行一些最小的模式匹配:
SELECT whatever FROM someTable WHERE someColumn LIKE '[C][0-9]%'
对于MySQL或PostgreSQL,语法可能会有所不同,但是一些快速搜索应该能找到正确的方法。
英文:
We need to know which database you're using to give you a proper answer. The fact that you're using ColdFusion has no bearing on the structure of the SQL you need to generate.
If you're using SQL Server, SQLShack says you should be able to use the like
operator with some minimal pattern matching:
SELECT whatever FROM someTable WHERE someColumn LIKE '[C][0-9]%'
The syntax will likely be different for MySQL or Postgresql, but some quick searches should turn up the proper approach.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论