Hi y'all!
I'm new to all of this so my question is probably dumb but I'll risk it anyway since I can't find my answer anywhere. I want to fill a Gridview from a sql query and all is well except for one field. The MAX function is needed (I think) to get the last date from a table but I cannot name the new column with the AS clause. When I run the query in SQL Manager it produces the correct result but the column I'm after says (No column name) at the top. Any thoughts on how to assign a name to this column.
I'll include the query below.
SELECT DISTINCT ContactExtendedProperties.ActiveStatus, Contacts.LastName, Contacts.FirstName,
ContactExtendedProperties.WelcomeCard, ContactExtendedProperties.BeforePic, ContactExtendedProperties.AfterPic,
NeedsTable.Description, ContactExtendedProperties.CurrentStatus, ContactExtendedProperties.SpacesCompleted,
ContactExtendedProperties.ClientLongevity,
(SELECT MAX(ContactFollowup.DateOfFollowup) AS DateOfFollowup FROM ContactFollowup),
ContactExtendedProperties.ReceivedEval, ContactExtendedProperties.OncancellationList
FROM Contacts
INNER JOIN ContactExtendedProperties ON Contacts.ContactId = ContactExtendedProperties.ContactId
INNER JOIN ClientStatus ON Contacts.ClientStatusId = ClientStatus.StatusId
INNER JOIN ContactFollowup ON Contacts.ContactId = ContactFollowup.ContactId
INNER JOIN RO_Users ON Contacts.PrimaryConsultantId = RO_Users.UserId
INNER JOIN ContactToNeeds ON Contacts.ContactId = ContactToNeeds.ContactId
INNER JOIN NeedsTable ON ContactToNeeds.NeedsId = NeedsTable.NeedId
WHERE Clientstatus.StatusDesc LIKE '%Client%'
Any help is appreciated.
Fred
I'm new to all of this so my question is probably dumb but I'll risk it anyway since I can't find my answer anywhere. I want to fill a Gridview from a sql query and all is well except for one field. The MAX function is needed (I think) to get the last date from a table but I cannot name the new column with the AS clause. When I run the query in SQL Manager it produces the correct result but the column I'm after says (No column name) at the top. Any thoughts on how to assign a name to this column.
I'll include the query below.
SELECT DISTINCT ContactExtendedProperties.ActiveStatus, Contacts.LastName, Contacts.FirstName,
ContactExtendedProperties.WelcomeCard, ContactExtendedProperties.BeforePic, ContactExtendedProperties.AfterPic,
NeedsTable.Description, ContactExtendedProperties.CurrentStatus, ContactExtendedProperties.SpacesCompleted,
ContactExtendedProperties.ClientLongevity,
(SELECT MAX(ContactFollowup.DateOfFollowup) AS DateOfFollowup FROM ContactFollowup),
ContactExtendedProperties.ReceivedEval, ContactExtendedProperties.OncancellationList
FROM Contacts
INNER JOIN ContactExtendedProperties ON Contacts.ContactId = ContactExtendedProperties.ContactId
INNER JOIN ClientStatus ON Contacts.ClientStatusId = ClientStatus.StatusId
INNER JOIN ContactFollowup ON Contacts.ContactId = ContactFollowup.ContactId
INNER JOIN RO_Users ON Contacts.PrimaryConsultantId = RO_Users.UserId
INNER JOIN ContactToNeeds ON Contacts.ContactId = ContactToNeeds.ContactId
INNER JOIN NeedsTable ON ContactToNeeds.NeedsId = NeedsTable.NeedId
WHERE Clientstatus.StatusDesc LIKE '%Client%'
Any help is appreciated.
Fred