The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Concatenate fields in select query?

Last post 08-22-2007, 2:09 PM by kwilder. 4 replies.
Sort Posts: Previous Next
  •  08-22-2007, 11:14 AM 4679

    Concatenate fields in select query?

    I saw this post on how to create new extended properties for SQL Server.  I can't get this to work for MySql.  Is there a different syntax?

    http://community.entityspaces.net/forums/thread/50.aspx 

    I want to populate a list box in this format: InquiryDate - LastName, FirstName.
     

    Thanks,

    King Wilder 


    King Wilder
    http://www.kingwilder.com
  •  08-22-2007, 12:00 PM 4681 in reply to 4679

    Re: Concatenate fields in select query?

    The only difference would be the brackets, in Microsoft SQL it's [ ] in MySql it's those string backslashes like `

    However, it would help if you woud expound on "Can't get it to work" ... Wink


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-22-2007, 12:55 PM 4683 in reply to 4681

    Re: Concatenate fields in select query?

     

    Mike.Griffin:

    The only difference would be the brackets, in Microsoft SQL it's [ ] in MySql it's those string backslashes like `

    However, it would help if you woud expound on "Can't get it to work" ... Wink

    This is my error:

     

    Code:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version 
    for the right syntax to use near '` + ` - ` + `LastName` + `, ` + `FirstName` as `NameWithDate``
    FROM `inquiry`' at line 1

     

    And this is my C# method:

     

    Code:
            public static InquiryCollection FetchAll()
    {
    InquiryCollection inqColl = new InquiryCollection();
    // inqColl.Query.Select(inqColl.Query.InquiryID, inqColl.Query.InquiryDate, inqColl.Query.FirstName, inqColl.Query.LastName, "`InquiryDate` + ` - ` + `LastName` + `, ` + `FirstName` as `NameWithDate`");
    inqColl.Query.Load();

    return inqColl;
    }

    King Wilder
    http://www.kingwilder.com
  •  08-22-2007, 1:08 PM 4684 in reply to 4683

    Re: Concatenate fields in select query?

    We pass whatever is in those < > brackets straight through to the database, just get the syntax right in MySQL and plug it in there.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-22-2007, 2:09 PM 4686 in reply to 4684

    Re: Concatenate fields in select query?

    Mike.Griffin:
    We pass whatever is in those < > brackets straight through to the database, just get the syntax right in MySQL and plug it in there.

    I had tried the < > brackets but they didn't work either.  MySql is very tricky to get right.  I did finally come up with a solution that did incorporate the brackets.

     

    Code:
            public static InquiryCollection FetchAll()
    {
    InquiryCollection inqColl = new InquiryCollection();
    // inqColl.Query.Select(inqColl.Query.InquiryID, inqColl.Query.InquiryDate, inqColl.Query.FirstName, inqColl.Query.LastName , "&lt;CONCAT(DATE(`InquiryDate`),_latin1' - ',`FirstName`,_latin1' ',`LastName`) AS NameWithDate>");
    inqColl.Query.Load();

    return inqColl;
    }

     

    The result is: 2007-08-14 - Joe Smith

    Thanks. 


    King Wilder
    http://www.kingwilder.com
View as RSS news feed in XML