views:

108

answers:

3

Is there a way to query against a concatenated field using MS SQL? For instance, what I want to do is something like:

Select FirstName+' '+LastName as FullName from Attendees where FullName like '%Joe Schmoe%'

The above doesn't work. What I have found works is:

Select * from Attendee where FirstName+' '+LastName like '%Joe Schmoe%'

but I can't figure out how to do that using a SubSonic SqlQuery. I have a number of joins and OR statements added dynamically that I don't want to have to write out the sql manually.

Any help/ideas?

A: 

how about this:

SELECT FullName 
FROM (SELECT FirstName+' '+LastName as FullName 
      FROM Attendees) X
WHERE FullName LIKE '%Joe Schmoe%'
Peter Carrero
Can you point me to how to do that with SubSonic? I have no problem writing a straight SQL query that works. I just need to be able to do it with SubSonic.
jwynveen
A: 

You can just specify your condition in the Where part of your query as follows:

List<Attendee> cardHolders = new YourDB()
  .Select
  .From<Attendee>()
  .Where(AttendeeTable.FirstNameColumn + " + ' ' + " + AttendeeTable.SurnameColumn + " AS FullName")
  .Like("%Joe Schmoe%")
  .ExecuteTypedList<Attendee>();
Adam
Unfortunately this renders sql that looks like "OR FirstName + ' ' + LastName LIKE @FirstName+''+LastName14" which is an invalid variable declaration.
jwynveen
Weird, works fine for me. What if you try (AttendeeTable.FirstNameColumn + " + ' ' + " + AttendeeTable.SurnameColumn + " AS FullName")
Adam
A: 

It seems it isn't possible in SubSonic

jwynveen