Re: 14 byte date/time in file name
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Tue, 10 Nov 2009 08:14:03 +0000 (UTC)
Jeroen Mostert (jmostert@xxxxxxxxx) writes:
Yes, that occurred to me as well, but my thoughts were running in another
direction altogether.
DECLARE @x VARCHAR(19);
DECLARE @i INT;
SELECT @x = CONVERT(CHAR(19), GETDATE(), 120), @i = 5;
SELECT @x = STUFF(@x, @i, 1, ''), @i = @i + 2;
SELECT @x = STUFF(@x, @i, 1, ''), @i = @i + 2;
SELECT @x = STUFF(@x, @i, 1, ''), @i = @i + 2;
SELECT @x = STUFF(@x, @i, 1, ''), @i = @i + 2;
SELECT @x = STUFF(@x, @i, 1, ''), @i = @i + 2;
SELECT @x;
Note how I unrolled a loop here for efficiency.[*]
I was unable to find something even more roundabout without it becoming
too far-fetched; I blame T-SQL's limited expressiveness.
Reminds of when I as a senior student and helped evaluating the tests of the
younger students in the basic programming course. In my batch there was a
guy who had written the same code six times, rather than writing a loop.
(The problem related to a dice.) I wanted to fluke him, since he apparently
had missed an important point. But the teacher who reviewed my ratings,
said we had to approve him, since his code after all worked correctly.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- References:
- 14 byte date/time in file name
- From: Himansu
- Re: 14 byte date/time in file name
- From: Erland Sommarskog
- Re: 14 byte date/time in file name
- From: Jeroen Mostert
- Re: 14 byte date/time in file name
- From: Plamen Ratchev
- Re: 14 byte date/time in file name
- From: Jeroen Mostert
- 14 byte date/time in file name
- Prev by Date: Re: Why can't recursive queries contain...?
- Next by Date: Re: Making content more readable -- please help!!
- Previous by thread: Re: 14 byte date/time in file name
- Next by thread: Re: 14 byte date/time in file name
- Index(es):
Relevant Pages
|