Converting ORDER BY with multiple case statements












1














I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?



 SELECT   
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc


My convertion without case statement below,



objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();









share|improve this question
























  • Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
    – MickyD
    Nov 23 '18 at 6:48
















1














I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?



 SELECT   
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc


My convertion without case statement below,



objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();









share|improve this question
























  • Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
    – MickyD
    Nov 23 '18 at 6:48














1












1








1







I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?



 SELECT   
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc


My convertion without case statement below,



objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();









share|improve this question















I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?



 SELECT   
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc


My convertion without case statement below,



objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();






c# linq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 6:14









Uwe Keim

27.4k31128210




27.4k31128210










asked Nov 23 '18 at 5:50









Sivaraj Ganesan

168




168












  • Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
    – MickyD
    Nov 23 '18 at 6:48


















  • Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
    – MickyD
    Nov 23 '18 at 6:48
















Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48




Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48












3 Answers
3






active

oldest

votes


















0














Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs



objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();





share|improve this answer





















  • Thanks @irfandar
    – Sivaraj Ganesan
    Nov 23 '18 at 9:02



















0














You should be able to do this using a Ternary Operator.



The ternary operator lets you convert a somewhat long-winded if/else statement into a single line. For example:



int a;
if(test) {
a = 1;
} else {
a = 2;
}


Can get converted into:



int a = test ? 1 : 2;


More complicated expressions can also be made by using multiple ternary expressions.



e.g.



int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}


Can be converted into this:



int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else


Alternatively formatted as:



int a = (testA ? 1 : (testB ? 2 : 3));


In your scenario, the ternary operator can be used in the orderby clause:



objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();


Check out the MSDN docs for more info.






share|improve this answer





















  • Thank You @Atin
    – Sivaraj Ganesan
    Nov 23 '18 at 9:04



















0














Done this by mywork. using ThenBy



objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441251%2fconverting-order-by-with-multiple-case-statements%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs



    objTypeDefLst = (from t1 in objTypeDefLst
    join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
    select new TypeDefinition
    {
    ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
    }).ToList();





    share|improve this answer





















    • Thanks @irfandar
      – Sivaraj Ganesan
      Nov 23 '18 at 9:02
















    0














    Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs



    objTypeDefLst = (from t1 in objTypeDefLst
    join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
    select new TypeDefinition
    {
    ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
    }).ToList();





    share|improve this answer





















    • Thanks @irfandar
      – Sivaraj Ganesan
      Nov 23 '18 at 9:02














    0












    0








    0






    Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs



    objTypeDefLst = (from t1 in objTypeDefLst
    join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
    select new TypeDefinition
    {
    ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
    }).ToList();





    share|improve this answer












    Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs



    objTypeDefLst = (from t1 in objTypeDefLst
    join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
    select new TypeDefinition
    {
    ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
    }).ToList();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 6:35









    irfandar

    1,0321016




    1,0321016












    • Thanks @irfandar
      – Sivaraj Ganesan
      Nov 23 '18 at 9:02


















    • Thanks @irfandar
      – Sivaraj Ganesan
      Nov 23 '18 at 9:02
















    Thanks @irfandar
    – Sivaraj Ganesan
    Nov 23 '18 at 9:02




    Thanks @irfandar
    – Sivaraj Ganesan
    Nov 23 '18 at 9:02













    0














    You should be able to do this using a Ternary Operator.



    The ternary operator lets you convert a somewhat long-winded if/else statement into a single line. For example:



    int a;
    if(test) {
    a = 1;
    } else {
    a = 2;
    }


    Can get converted into:



    int a = test ? 1 : 2;


    More complicated expressions can also be made by using multiple ternary expressions.



    e.g.



    int a;
    if(testA) {
    a = 1;
    } else if(testB) {
    a = 2;
    } else {
    a = 3;
    }


    Can be converted into this:



    int a = testA ? 1 : // if(testA)
    testB ? 2 : // else if(testB)
    3; // else


    Alternatively formatted as:



    int a = (testA ? 1 : (testB ? 2 : 3));


    In your scenario, the ternary operator can be used in the orderby clause:



    objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
    on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby
    ((t1.TypeDefDesc == "Successful" &&
    t1.TypeDefGroup == "ResponseType") ? 1 :
    (t1.TypeDefDesc == "Failed" &&
    t1.TypeDefGroup == "ResponseType") ? 2 :
    (t1.TypeDefDesc == "Failed Attempt" &&
    t1.TypeDefGroup == "ResponseType") ? 3 :
    4) // Whatever the "else" group is
    select new TypeDefinition {
    ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
    }).ToList();


    Check out the MSDN docs for more info.






    share|improve this answer





















    • Thank You @Atin
      – Sivaraj Ganesan
      Nov 23 '18 at 9:04
















    0














    You should be able to do this using a Ternary Operator.



    The ternary operator lets you convert a somewhat long-winded if/else statement into a single line. For example:



    int a;
    if(test) {
    a = 1;
    } else {
    a = 2;
    }


    Can get converted into:



    int a = test ? 1 : 2;


    More complicated expressions can also be made by using multiple ternary expressions.



    e.g.



    int a;
    if(testA) {
    a = 1;
    } else if(testB) {
    a = 2;
    } else {
    a = 3;
    }


    Can be converted into this:



    int a = testA ? 1 : // if(testA)
    testB ? 2 : // else if(testB)
    3; // else


    Alternatively formatted as:



    int a = (testA ? 1 : (testB ? 2 : 3));


    In your scenario, the ternary operator can be used in the orderby clause:



    objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
    on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby
    ((t1.TypeDefDesc == "Successful" &&
    t1.TypeDefGroup == "ResponseType") ? 1 :
    (t1.TypeDefDesc == "Failed" &&
    t1.TypeDefGroup == "ResponseType") ? 2 :
    (t1.TypeDefDesc == "Failed Attempt" &&
    t1.TypeDefGroup == "ResponseType") ? 3 :
    4) // Whatever the "else" group is
    select new TypeDefinition {
    ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
    }).ToList();


    Check out the MSDN docs for more info.






    share|improve this answer





















    • Thank You @Atin
      – Sivaraj Ganesan
      Nov 23 '18 at 9:04














    0












    0








    0






    You should be able to do this using a Ternary Operator.



    The ternary operator lets you convert a somewhat long-winded if/else statement into a single line. For example:



    int a;
    if(test) {
    a = 1;
    } else {
    a = 2;
    }


    Can get converted into:



    int a = test ? 1 : 2;


    More complicated expressions can also be made by using multiple ternary expressions.



    e.g.



    int a;
    if(testA) {
    a = 1;
    } else if(testB) {
    a = 2;
    } else {
    a = 3;
    }


    Can be converted into this:



    int a = testA ? 1 : // if(testA)
    testB ? 2 : // else if(testB)
    3; // else


    Alternatively formatted as:



    int a = (testA ? 1 : (testB ? 2 : 3));


    In your scenario, the ternary operator can be used in the orderby clause:



    objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
    on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby
    ((t1.TypeDefDesc == "Successful" &&
    t1.TypeDefGroup == "ResponseType") ? 1 :
    (t1.TypeDefDesc == "Failed" &&
    t1.TypeDefGroup == "ResponseType") ? 2 :
    (t1.TypeDefDesc == "Failed Attempt" &&
    t1.TypeDefGroup == "ResponseType") ? 3 :
    4) // Whatever the "else" group is
    select new TypeDefinition {
    ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
    }).ToList();


    Check out the MSDN docs for more info.






    share|improve this answer












    You should be able to do this using a Ternary Operator.



    The ternary operator lets you convert a somewhat long-winded if/else statement into a single line. For example:



    int a;
    if(test) {
    a = 1;
    } else {
    a = 2;
    }


    Can get converted into:



    int a = test ? 1 : 2;


    More complicated expressions can also be made by using multiple ternary expressions.



    e.g.



    int a;
    if(testA) {
    a = 1;
    } else if(testB) {
    a = 2;
    } else {
    a = 3;
    }


    Can be converted into this:



    int a = testA ? 1 : // if(testA)
    testB ? 2 : // else if(testB)
    3; // else


    Alternatively formatted as:



    int a = (testA ? 1 : (testB ? 2 : 3));


    In your scenario, the ternary operator can be used in the orderby clause:



    objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
    on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
    where t1.TypeDefGroup == strTypeDefGrp
    orderby
    ((t1.TypeDefDesc == "Successful" &&
    t1.TypeDefGroup == "ResponseType") ? 1 :
    (t1.TypeDefDesc == "Failed" &&
    t1.TypeDefGroup == "ResponseType") ? 2 :
    (t1.TypeDefDesc == "Failed Attempt" &&
    t1.TypeDefGroup == "ResponseType") ? 3 :
    4) // Whatever the "else" group is
    select new TypeDefinition {
    ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
    }).ToList();


    Check out the MSDN docs for more info.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 6:37









    AtinSkrita

    958712




    958712












    • Thank You @Atin
      – Sivaraj Ganesan
      Nov 23 '18 at 9:04


















    • Thank You @Atin
      – Sivaraj Ganesan
      Nov 23 '18 at 9:04
















    Thank You @Atin
    – Sivaraj Ganesan
    Nov 23 '18 at 9:04




    Thank You @Atin
    – Sivaraj Ganesan
    Nov 23 '18 at 9:04











    0














    Done this by mywork. using ThenBy



    objTypeDefLst = (from t1 in objTypeDefLst
    join t2 in objTypeDefLst
    on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
    where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
    select new TypeDefinition
    {
    ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
    ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
    }).ToList();
    objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
    .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
    .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();





    share|improve this answer


























      0














      Done this by mywork. using ThenBy



      objTypeDefLst = (from t1 in objTypeDefLst
      join t2 in objTypeDefLst
      on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
      where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
      select new TypeDefinition
      {
      ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
      ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
      }).ToList();
      objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
      .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
      .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();





      share|improve this answer
























        0












        0








        0






        Done this by mywork. using ThenBy



        objTypeDefLst = (from t1 in objTypeDefLst
        join t2 in objTypeDefLst
        on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
        where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
        select new TypeDefinition
        {
        ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
        ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
        }).ToList();
        objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
        .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
        .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();





        share|improve this answer












        Done this by mywork. using ThenBy



        objTypeDefLst = (from t1 in objTypeDefLst
        join t2 in objTypeDefLst
        on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
        where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
        select new TypeDefinition
        {
        ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
        ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
        }).ToList();
        objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
        .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
        .ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 8:58









        Sivaraj Ganesan

        168




        168






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441251%2fconverting-order-by-with-multiple-case-statements%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Basket-ball féminin

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

            I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...