Comparing three Comma separated values in SQL

妖精的绣舞 提交于 2019-12-12 01:39:28

问题


Comparing two comma separated values in sql, we can get done by using Split kind of functions.(Three columns also we can do !) But, without using the functions is that possible?

Let me give an example.

The query should check the following conditions

(1) Select the tasks from Table- 1 That is Planned. But Not in done or declined columns.

(2) Return only the mandatory tasks

Using Split functionality(UD Functions) or Cursor is making query more complex and it swallows the time as well.

Is there any alternative solution to get this done? Possible with single query ?

Thanks in advance.


回答1:


No there is no magic bullet. If you really want to increase performance this could be normalized (maybe indexed). Also, more standard queries would work without a split function.

Depending on the exact situation it might be different but from what you show I would have a tasks table with one row for every task that related to table1 which appears to be 'jobs' or 'projects' that contain many tasks.

Just being in the table means that they are planned tasks with columns for mandatory, declined and completed.

If you can not normalize this data then you are likely stuck with split functions. There are articles about getting great performance from split functions with CLR functions appearing to run quite fast.



来源:https://stackoverflow.com/questions/39724781/comparing-three-comma-separated-values-in-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!