【问题标题】:Concatenate Columns in Linq to SQL Select将 Linq 中的列连接到 SQL Select
【发布时间】:2016-07-14 04:23:52
【问题描述】:

我想根据一列的条件连接两列值。

我正在尝试这样

select
{
     Orders=r.ordercode.length==0?r.order1:r.ordercode.length==3?r.order1+r.order2+r.order3
}

【问题讨论】:

  • 我找到了解决方案
  • 那是什么?您可以自己回答,以便其他人也知道。 :)

标签: sql-server linq linq-to-sql linq-to-entities linq-to-xml


【解决方案1】:

试试这个

select
{
     Orders = (
                (r.ordercode.length == 0 || r.ordercode.length == 3) ? 
                    String.Format("{0}, {1}, {2}", r.order1, r.order2, r.order3) : 
                    String.Empty
              )
}

【讨论】:

    【解决方案2】:

    订单=r.ordercode.length==0?r.order1:r.ordercode.length==3?string.concat(r.order1,", ",r.order2,", ",r.order3 ):""

    【讨论】:

    • 我想要 order1 if length==0 if length==3 i to concat orders 1 to 3 else just display nothing so used ""
    • 请检查我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 2021-05-07
    • 2014-08-08
    相关资源
    最近更新 更多