From: DavidC on
I have an SQL SELECT (see below) that I want to have the column named
ActivityDate display as either a date and time or just a date. For example,
if the time is anything other than 12:00 AM then I want to show the date and
time, otherwise, just the date. Thanks.

SELECT [ActivityID],
[PeopleLinkID],
[ActivityCode],
[ActivityDate],
[EnteredBy],
[ActivityNotes
FROM [vw_ActivityHistoryCaseNotes]
WHERE ([ActivityID] = @ActivityID)

--
David
From: Plamen Ratchev on
You can convert to string and based on that manipulate:

SELECT [ActivityID],
[PeopleLinkID],
[ActivityCode],
CASE WHEN RIGHT(CONVERT(VARCHAR(19), [ActivityDate], 100), 7) = '12:00AM'
THEN LEFT(CONVERT(VARCHAR(19), [ActivityDate], 100), 11)
ELSE CONVERT(VARCHAR(19), [ActivityDate], 100)
END AS [ActivityDate],
[EnteredBy],
[ActivityNotes]
FROM [vw_ActivityHistoryCaseNotes]
WHERE [ActivityID] = @ActivityID;

--
Plamen Ratchev
http://www.SQLStudio.com
From: --CELKO-- on
>> I have an SQL SELECT (see below) that I want to have the column named activity_date display as either a date and time or just a date. <<

The whole idea of a tiered architecture is that display is done in the
front end and never in the database. The kludge you can use to be a
really bad SQL programmer is to waste time by casting temporal data
into a string, then editing the string for display.
From: DavidC on
You got my attention. I am using the result set in an asp.net web form. How
would I set the formatting to show just a date or conditionally show date and
time? I know how to format each one but have no idea how to do it
conditionally so that Is why I chose the SQL route. Thanks for any
additional help.
--
David


"--CELKO--" wrote:

> >> I have an SQL SELECT (see below) that I want to have the column named activity_date display as either a date and time or just a date. <<
>
> The whole idea of a tiered architecture is that display is done in the
> front end and never in the database. The kludge you can use to be a
> really bad SQL programmer is to waste time by casting temporal data
> into a string, then editing the string for display.
> .
>