locked
Write Plugin from Sql query RRS feed

  • Question

  • Hi Experts,

    I have a sql query which is below

    select pager as recordno  from Contact where ParentCustomerId='A8697ED6-9334-E211-99AA-080027E18CA8'

    How can I write and store it using plugin?


    • Edited by Ashis_K Friday, November 23, 2012 10:04 AM
    Friday, November 23, 2012 10:03 AM

Answers

  • hi,

    you can do this

    QueryExpression _Query = new QueryExpression
                {
                    EntityName = "contact",
                    ColumnSet = new ColumnSet(new String[] { "pager",}),
                    Criteria =
                    {
                        
                        Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName="parentcustomerid",
                                    Operator=ConditionOperator.Equal,
                                    Values={"A8697ED6-9334-E211-99AA-080027E18CA8"}
    
                                }
                            }
                    }
    
                };
    
                EntityCollection _Entities = service.RetrieveMultiple(_Query);


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by MubasherSharif Friday, November 23, 2012 10:49 AM
    • Marked as answer by Ashis_K Friday, November 23, 2012 11:13 AM
    Friday, November 23, 2012 10:16 AM
  • hi 

    add this snippet.

    _Query.AddOrder("pager", OrderType.Ascending);
    
    
    _Query.AddOrder("pager", OrderType.Descending);



    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Ashis_K Friday, November 23, 2012 12:51 PM
    Friday, November 23, 2012 11:28 AM

All replies

  • hi,

    you can do this

    QueryExpression _Query = new QueryExpression
                {
                    EntityName = "contact",
                    ColumnSet = new ColumnSet(new String[] { "pager",}),
                    Criteria =
                    {
                        
                        Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName="parentcustomerid",
                                    Operator=ConditionOperator.Equal,
                                    Values={"A8697ED6-9334-E211-99AA-080027E18CA8"}
    
                                }
                            }
                    }
    
                };
    
                EntityCollection _Entities = service.RetrieveMultiple(_Query);


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by MubasherSharif Friday, November 23, 2012 10:49 AM
    • Marked as answer by Ashis_K Friday, November 23, 2012 11:13 AM
    Friday, November 23, 2012 10:16 AM
  • Again thank you CRMIG for your valuable answer.

    Can you please write me how I will put order by in the above query to sort my pager value.

    Friday, November 23, 2012 11:14 AM
  • hi 

    add this snippet.

    _Query.AddOrder("pager", OrderType.Ascending);
    
    
    _Query.AddOrder("pager", OrderType.Descending);



    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by Ashis_K Friday, November 23, 2012 12:51 PM
    Friday, November 23, 2012 11:28 AM