如何优化嵌套条件SQL Server查询2008R2(How to optimize nested conditional SQL Server Query 2008R2)
if {condition1} = '0' begin if {condition2} = 'Yes' Begin Set @SQLQuery = @SQLQuery + ' AND ' end else begin Set @SQLQuery = @SQLQuery + ' AND ' end endif {condition1} = '0' begin if {condition2} = 'Yes' Begin Set @SQLQuery = @SQLQuery + ' AND ' end else begin Set @SQLQuery = @SQLQuery + ' AND ' end end
原文:https://stackoverflow.com/questions/37066834
更新时间:2022-01-20 10:01
最满意答案
如果两个列表都是有序的,您可以使用
Zip
扩展方法:tokens.Cast<TokensEnum>().Zip(names, (t, n) => Tuple.Create(t, n));
这将返回
IEnumerable<Tuple<TokensEnum, string>>
。但正如Jon Skeet所暗示的那样 ,在这种情况下,做这样的事情可能会更容易:
Enum.GetValues(typeof(TokensEnum)) .Cast<TokensEnum>() .Select(t => Tuple.Create(t, t.ToString()));
这将返回与上面相同的结果,但它将在一个步骤中完成。
既然你在评论中提到你想要一个
Dictionary<string, TokensEnum>
,你可以使用这样的东西来构造它:Dictionary<string, TokensEnum> myDictionary = Enum.GetValues(typeof(TokensEnum)) .Cast<TokensEnum>() .ToDictionary(t => t.ToString());
If both lists are in order, you can use the
Zip
extension method:tokens.Cast<TokensEnum>().Zip(names, (t, n) => Tuple.Create(t, n));
This will return an
IEnumerable<Tuple<TokensEnum, string>>
.But as Jon Skeet suggests, in this case, it would probably be easier to do something like this:
Enum.GetValues(typeof(TokensEnum)) .Cast<TokensEnum>() .Select(t => Tuple.Create(t, t.ToString()));
This will return the same result as above, but it will do it in a single step.
Since you mentioned in your comments that you'd like to have a
Dictionary<string, TokensEnum>
, you can use something like this to construct it:Dictionary<string, TokensEnum> myDictionary = Enum.GetValues(typeof(TokensEnum)) .Cast<TokensEnum>() .ToDictionary(t => t.ToString());
相关问答
更多-
不同类型的链接列表!(Different Types of Linked Lists!)[2022-08-22]
展开的链接列表 在计算机编程中,展开的链接列表是在每个节点中存储多个元素的链接列表上的变体。 它可以显着提高缓存性能,同时减少与存储列表元数据(如引用)相关的内存开销。 它与B树有关。 - 维基百科 XOR链接列表 XOR链接列表是计算机编程中使用的数据结构。 它们利用按位异或(XOR)操作(这里用⊕表示)来减少双向链表的存储需求。 - 维基百科 Unrolled Linked List In computer programming, an unrolled linked list is a variat ... -
你可以使用not运算符'^'并说它可以是所有内容而不是下划线 - 如果匹配你有你的URL-它就像'[^ _] *'所有不是下划线的东西。 在grep命令上方使用'或'运算符插入,并且它将使用四位数字并且如果它们不包括下划线。 记得像这样逃避或运营商:'\ |' you can just use the not operator '^' and say that it can be everything but not the underscore - if match you have your URL- ...
-
比较通用列表的类型(Comparing types of generic lists)[2023-12-02]
是的,您正在比较两种类型: List和IList 。 它们不是同一类型,我不知道你为什么期望它们是相同的。 目前还不清楚你要做什么,但你可能想要使用Type.IsAssignableFrom 。 例如,在您的示例中, Console.WriteLine(type2.IsAssignableFrom(type1)); 将打印为True。 在编辑之前回答...... 无法重现: using System; using System.Collections.Generic; c ... -
Python - 在一个函数中展平两种不同类型的列表(Python - Flatten lists of lists of two different types in one function)[2022-05-23]
尝试; 对于list1 [sum(x, []) for x in list1] 对于list2 [sum(x, []) for a in list2 for x in a] 演示 >>> list1 = [[[0 , 0], [0, 1], [0 ,2]]] >>> list2 = [[[[0, 0] , [0, 1], [0, 2]], [[1, 0], [1, 1], [1 ,2]]]] >>> [sum(x, []) for x in list1] [[0, 0, 0, 1, 0, 2]] >>> ... -
C#中两种不同类型的列表(List of two different Types in C#)[2022-04-23]
使用界面: ICartListItem 并让你的名单是: List现在,创建几种类型,让它们全部实现这个接口,并且可以将它们全部安全地存储在列表中。 或者,如果您希望CartItem中存在某种默认逻辑,请使用基类而不是接口。 Use an interface: ICartListItem And make your list be: List Now, create several types, have all of them ... -
你可以这样做: class TypeA { var ID: Int init(_ id: Int) { self.ID = id } } class TypeB { var ID: Int init(_ id: Int) { self.ID = id } } struct Wrap { var ID: Int { return a?.ID ?? b?.ID ?? 0 } let a ...
-
不同类型的列表清单(List of Lists with different type)[2022-05-07]
使用object而不是dynamic ,你会有object列表,你可以稍后将其转换为所需的类型。 struct Column { public string title; public List -
如果两个列表都是有序的,您可以使用Zip扩展方法: tokens.Cast
().Zip(names, (t, n) => Tuple.Create(t, n)); 这将返回IEnumerable > 。 但正如Jon Skeet所暗示的那样 ,在这种情况下,做这样的事情可能会更容易: Enum.GetValues(typeof(TokensEnum)) .Cast () .Select(t => ... -
要么从公共基类派生它们,那么你会使用类似的 var humanBeings = orderedStudents.Cast
().Concat(orderedWorkers.Cast ()).ToList(); 或..将它们转换为公共基类:) object Either derive them from common base class and then you would use sth like var humanBeings = orderedStudents.Cast 相关文章
更多- SQL Server 压力测试
- Hadoop+SQL Server+Excel=大数据分析
- Lucene/Solr Optimize相关总结
- 《[窗内网]SQL 2008完全学习手册 视频教程》
- Solrflux源码分析-Sql Support within Solr-类Sql的solr搜索实现(2)
- 常用HQL(Hibernate Query Language)查询
- SQL Server 2000 如何锁定表中的行,使其他线程读取该行时候发生sql异常,不能读取?
- 如何优化这个sql语句
- 不会sql语句....谁帮我优化下
- 一个sql查询
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。