🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.vdbase.data.sql
Article #716

Re: Select Character + Numeric

#716
From: Steve Koterski
Date: Wed, 19 Aug 1998 00:00
51 lines
3118 bytes
On Wed, 19 Aug 1998 13:09:17 +0200, Romain@Do.not.reply.via.e-mail (Romain
Strieff [TeamB]) wrote:

>In article <35d52c67.8565065@forums.inprise.com>, 
>koterski@NOSPAMborland.com grudgingly admits...
>> 
>> The CAST function takes two parameters: the value to be converted (column,
>> literal, or calculated value) and the data type to which the value is to be
>> converted. In the case of the CHAR data type, you *must* supply a length
>> specification. For example:
>> 
>>   SELECT Name || CAST(NumberField AS CHAR(10))
>>   FROM YourTable
>> 
>Does that also work for extracting the date-portion alone of a datetime 
>field?

Kinda. It does not extract so much as truncate. A DATE or TIMESTAMP type
column can be converted to DATE. The time portion of the TIMESTAMP column
is simply lopped off. Conversely, a DATE column converted to TIMESTAMP
acquires a default time (12:00:00 AM). In the example below, DT is a
TIMESTAMP column and D a DATE type column.

  SELECT CAST(DT AS DATE), CAST(D AS DATE),
    CAST(DT AS TIMESTAMP), CAST(D AS TIMESTAMP)
  FROM "WithDateTime.db"

A Paradox Time field cannot be converted using the CAST function to either
the DATE or TIMESTAMP data type. But a TIMESTAMP type column can be
converted to TIME type, the date portion simply being dropped from the
column's value. A DATE type column can only be converted to TIME if first
converted to TIMESTAMP. This is, of course, worthless and frivolous as
casting a DATE as TIMESTAMP produces only a default time value.

  SELECT CAST(DT AS TIME), CAST(CAST(D AS TIMESTAMP) AS TIME)
  FROM "WithDateTime.db"

Quoted DATE, TIMESTAMP, and TIME literals are automatically converted to
the appropriate data type based on the context in which they are used or
the column into which the literal value is placed. For instance, a quoted
TIMESTAMP literal is automatically converted to TIMESTAMP for use in a
Paradox DateTime field in an UPDATE statement.

  UPDATE "Employee.db"
  SET LastUpdate = "12/31/1999"

//////////////////////////////////////////////////////////////////////////
Steve Koterski                      "The knowledge of the world is only to
Technical Publications              be acquired in the world, and not in a
INPRISE Corporation                 closet."
http://www.inprise.com/delphi          -- Earl of Chesterfield (1694-1773)
Technical Details
Message-ID: <35e002ea.5594602@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6qhdmj$k8r8@forums.borland.com> <35CC45CE.8F82A5C8@ibm.net> <6qkgsd$ofg7@forums.borland.com> <35d52c67.8565065@forums.inprise.com> <MPG.104494b1d02e6edb98b06f@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff5a1,e0ca2689a5358a7a
X-Google-Attributes: gidff5a1,public
From: skoterski@NOSPAMinprise.com (Steve Koterski)
Subject: Re: Select Character + Numeric
Date: 1998/08/19
Message-ID: <35e002ea.5594602@forums.inprise.com>
X-Deja-AN: 382700200
Content-Transfer-Encoding: 7bit
References: <6qhdmj$k8r8@forums.borland.com> <35CC45CE.8F82A5C8@ibm.net> <6qkgsd$ofg7@forums.borland.com> <35d52c67.8565065@forums.inprise.com> <MPG.104494b1d02e6edb98b06f@forums.borland.com>
Content-Type: text/plain; charset=us-ascii
Organization: INPRISE Corporation, Technical Publications
Mime-Version: 1.0
Reply-To: skoterski@NOSPAMinprise.com
Newsgroups: borland.public.vdbase.data.sql