Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need to pad string values
Message
De
07/12/2001 10:29:27
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00591126
Message ID:
00591160
Vues:
28
Sergey,

Thank you for a perfect answer to my problem.

Regards

Peter

>You can use MS SQL Server specific function CONVERT for a better control over conversion
SELECT
>   Convert( char(10), [Interval], 102) AS Dates,
>   Replace(Convert( char(10), [Interval], 108), ':', '.') AS Times
>FROM dbo.Detail
>
or you can modify your code as follow
SELECT DISTINCT TOP 100 PERCENT Member_Id,
>	REPLACE( CAST(DATEPART(yyyy, [Interval]) AS char(4))
>		+ '.' + CAST(DATEPART(mm, [Interval]) AS char(2))
>		+ '.' + CAST(DATEPART(dd, [Interval]) AS char(2)), ' ', '0') AS Dates,
>	REPLACE( CAST(DATEPART(hh, [Interval]) AS char(2))
>		+ '.' + CAST(DATEPART(mi,[Interval]) AS char(2))
>		+ '.' + CAST(DATEPART(ss, [Interval]) AS char(2)), ' ', '0') AS Times
>FROM dbo.Detail
>
>
>>In the table there's a datetime column.
>>
>>The following syntax converts this to two char columns, and it works fine, and it's fast.
>>
>>
>>SELECT DISTINCT TOP 100 PERCENT Member_Id,
>>   RTRIM(CAST(DATEPART(yyyy, [Interval]) AS char))
>>   + '.' + RTRIM(CAST(DATEPART(mm, [Interval]) AS char))
>>   + '.' + RTRIM(CAST(DATEPART(dd, [Interval]) AS char)) AS Dates,
>>   RTRIM(CAST(DATEPART(hh, [Interval]) AS char))
>>   + '.' + RTRIM(CAST(DATEPART(mi,[Interval]) AS char))
>>   + '.' + RTRIM(CAST(DATEPART(ss, [Interval]) AS char)) AS Times
>>FROM dbo.Detail
>>
Peter Pirker


Whosoever shall not fall by the sword or by famine, shall fall by pestilence, so why bother shaving?

(Woody Allen)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform