Solved

Show milliseconds from SQL in Crystal Reports

Posted on 2014-03-22
14
732 Views
Last Modified: 2014-03-23
I have a datetime in SQL SERVER 2008 that shows up to milliseconds :
2014-03-22 11:35:33.450 and want to know if there is a way to show the milliseconds in Crystal Reports which only goes to seconds.

I need this as I'm sorting by exact time stamps and with only the seconds reflected I seem to have duplicate timestamp even though in SQL there is always a difference (milliseconds.
0
Comment
Question by:John-S Pretorius
  • 7
  • 5
  • 2
14 Comments
 
LVL 22

Expert Comment

by:Ido Millet
ID: 39948030
Use a Command, SQL Expression, SP, or a VIEW to Convert or Cast the DateTime into a String.
0
 
LVL 22

Assisted Solution

by:Ido Millet
Ido Millet earned 125 total points
ID: 39948041
This provides details on the Style argument required for the Convert() function:
http://www.w3schools.com/sql/func_convert.asp
Since you want to be able to sort on the resulting string, you need to use a style such as 121.  So this looks like a good choice:
CONVERT(VARCHAR(24), <Your_Date_Column>, 121)
0
 

Author Comment

by:John-S Pretorius
ID: 39948076
Thank you Ido,
I think this is what I'm looking for - Having trouble getting a SP together to convert this column (Time,{datetime},not null) within the dbo.ContractParkerMovements table.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39948229
It should be something like

SELECT  Convert(Varchar(24),ContractParkerMovements.Time,121) as strTime
FROM   ContractParkerMovements

mlmcc
0
 

Author Comment

by:John-S Pretorius
ID: 39948550
Thank you mlmcc, that works perfectly but I then loose all my other tables (doing this only show strTime) - how do I add this table and keep everything else in place.
0
 
LVL 22

Expert Comment

by:Ido Millet
ID: 39948564
That column expression is in addition to all your other columns. Not instead of.
0
 

Author Comment

by:John-S Pretorius
ID: 39948574
If I run(Execute) your statement (which is within a Stored Procedure)
SELECT  Convert(Varchar(24),ContractParkerMovements.Time,121) as strTime
FROM   ContractParkerMovements

I just get 1 table :-  strTime as a result
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:Ido Millet
ID: 39948578
Your SP already has a SELECT statement with several columns.  Add just the expression (without the SELECT and the FROM) as an additional column.
0
 

Author Comment

by:John-S Pretorius
ID: 39949248
My SP is based on an already complex built View (ContractParkerMovements):- (See below) so when I run your command :- Convert(Varchar(24),ContractParkerMovements.Time,121) as strTime I just get 1 new column Strtime
-------------------------------------------------------------------------------------------------------------------------

SELECT        1 AS Quantity, dbo.MVKARTEBEWEGUNG.Ztpkt AS Time, dbo.KUNDE.AnlagenNr AS FacilityNo, dbo.KUNDE.KundenNr AS CustomerNo,
                         dbo.KUNDE.Titel AS CustomerTitle, dbo.KUNDE.Nachname AS CustomerSurname, dbo.KUNDE.Vorname AS CustomerFirstName,
                         dbo.KUNDE.Strasse AS Street, dbo.KUNDE.Plz AS ZipCode, dbo.KUNDE.Ort AS City, dbo.SDSYSLAND.Landeskennung3 AS Country,
                         dbo.KUNDE.SteuerNr AS TaxCode, dbo.KUNDE.AusweisNr AS IdDocumentNo, dbo.KUNDE.Telefon AS Telephone, dbo.KUNDE.VertragsNr AS RentalAgmtNo,
                         dbo.KUNDE.VertragsbeginnDat AS RentalAgmtBeginDate, dbo.KUNDE.KuendigungsDat AS RentalAgmtTerminationDate, dbo.KUNDE.Kaution AS Deposit,
                         dbo.KUNDE.Maximalstand AS MaximumLevel, dbo.KUNDE.Iststand AS CurrentLevel, dbo.KUNDE.Bemerkung AS CustomerRemarks,
                         dbo.KUNDE.Bemerkung2 AS CustomerRemarks2, dbo.KUNDE.Bemerkung3 AS CustomerRemarks3, dbo.KUNDE.Abteilung AS CustomerDepartment,
                         dbo.KUNDE.EMail AS CustomerEmail, CAST(dbo.KUNDE.IstGesp AS tinyint) AS RentalAgmtIsBlocked, dbo.KUNDE.GespAbDat AS RentalAgmtBlockedDate,
                         dbo.BENUTZER.BenutzerNr AS UserNo, dbo.BENUTZER.Titel AS UserTitle, dbo.BENUTZER.Nachname AS UserSurname,
                         dbo.BENUTZER.Vorname AS UserFirstName, dbo.BENUTZER.GeburtsDat AS UserDateOfBirth, dbo.BENUTZER.StellplatzNr AS UserSpaceNo,
                         dbo.BENUTZER.Bemerkung AS UserRemarks, dbo.BENUTZER.Bemerkung2 AS UserRemarks2, dbo.BENUTZER.Bemerkung3 AS UserRemarks3,
                         dbo.BENUTZER.Abteilung AS UserDepartment, dbo.BENUTZER.EMail AS UserEmail, dbo.BENUTZER.IdentifikationsNr AS UserIdTag,
                         dbo.MVKARTE.ArtikNr AS ArticleNo, dbo.MVKARTE.VonDat AS CardValidFrom, dbo.MVKARTE.BisDat AS CardValidUntil,
                         dbo.MVKARTE.KarenziertVonDat AS SuspendPeriodFrom, dbo.MVKARTE.KarenziertBisDat AS SuspendPeriodUntil,
                         dbo.MVKARTE.ProdStatus AS CardProductionStatus, dbo.MVKARTE.ProdGrund AS CardProductionReason, CAST(dbo.MVKARTE.IstNeutral AS tinyint)
                         AS CardIsNeutral, CAST(dbo.MVKARTE.IstEinmalneutral AS tinyint) AS CardIsSingleNeutral, CAST(dbo.MVKARTE.IstGesp AS tinyint) AS CardIsBlocked,
                         dbo.MVKARTE.GespAbDat AS CardBlockedDate, dbo.MVKARTEBEWEGUNG.Restwert AS CardRemainingValue,
                         dbo.MVKARTEBEWEGUNG.WaehrungRestwert AS CurrencyRemainingValue, dbo.MVKARTE.Kartentyp AS CardType,
                         dbo.sd_mask_seriennummer(RTRIM(CONVERT(nvarchar(30), DecryptByKey(dbo.MVKARTE.SerienNr))), dbo.MVKARTE.Kartenart) AS SerialNo,
                         dbo.MVKARTE.Kartenart AS CardNoMask, dbo.ARTIK.ArtikBez AS ArticleDesig, dbo.ARTIK.ArtikKbez AS ArticleAbbr, dbo.SDSYSTXT.Txt AS ArticleCategory,
                         dbo.sd_cardno(dbo.MVKARTE.PhNr, dbo.MVKARTE.AnlageZtpkt, dbo.MVKARTE.KartenNr) AS CardNo,
                         dbo.MVKARTEBEWEGUNG.Bewegung AS MovementType, dbo.MVKARTEBEWEGUNG.AnlagenNr AS MovementFacilityNo,
                         dbo.MVKARTEBEWEGUNG.PhNr AS CarparkNo, dbo.MVKARTEBEWEGUNG.PhBez AS CarparkDesig, dbo.MVKARTEBEWEGUNG.GerNr AS DeviceNo,
                         dbo.MVKARTEBEWEGUNG.GerBez AS DeviceDesig, dbo.MVKARTEBEWEGUNG.Betrag AS Amount,
                         dbo.MVKARTEBEWEGUNG.WaehrungBetrag AS CurrencyOfAmount, dbo.MVKARTEBEWEGUNG.Txt AS AdditionalInfo,
                         SDSYSTXT_NATIONALITEAT.Txt AS Nationality, dbo.MVKARTEBEWEGUNG.Kartenwertart AS CardValueType,
                         dbo.MVKARTEBEWEGUNG.AbweisungsNr AS RejectionNo, SDSYSTXT_ABWEISUNG.Txt AS RejectionDesig, dbo.KUNDE.BuchhaltungsNr AS AccountingNo,
                         dbo.MVKARTEBEWEGUNG.VonZtpkt AS PaidFrom, SDSYSTXT_BEWEGUNG.Txt AS MovementTypeDesig, dbo.ANLAGE.AnlagenBez AS FacilityDesig,
                         dbo.ANLAGE.AnlagenKbez AS FacilityAbbr
FROM            dbo.PARAM AS PARAM_NATIONALITAET WITH (NOLOCK) INNER JOIN
                         dbo.SDSYSTXT AS SDSYSTXT_NATIONALITEAT WITH (NOLOCK) ON PARAM_NATIONALITAET.Sprache = SDSYSTXT_NATIONALITEAT.Sprache INNER JOIN
                         dbo.BENUTZER WITH (NOLOCK) INNER JOIN
                         dbo.KUNDE WITH (NOLOCK) ON dbo.BENUTZER.KundenNr = dbo.KUNDE.KundenNr AND dbo.BENUTZER.AnlagenNr = dbo.KUNDE.AnlagenNr INNER JOIN
                         dbo.MVKARTE WITH (NOLOCK) ON dbo.BENUTZER.BenutzerNr = dbo.MVKARTE.BenutzerNr AND
                         dbo.BENUTZER.AnlagenNr = dbo.MVKARTE.AnlagenNr INNER JOIN
                         dbo.ARTIK WITH (NOLOCK) ON dbo.MVKARTE.ArtikNr = dbo.ARTIK.ArtikNr INNER JOIN
                         dbo.KARTENARTIK WITH (NOLOCK) ON dbo.MVKARTE.ArtikNr = dbo.KARTENARTIK.ArtikNr INNER JOIN
                         dbo.SDSYSKART WITH (NOLOCK) ON dbo.KARTENARTIK.Syskart = dbo.SDSYSKART.Syskart INNER JOIN
                         dbo.SDSYSTXT WITH (NOLOCK) ON dbo.SDSYSKART.BezTxtCode = dbo.SDSYSTXT.TxtCode INNER JOIN
                         dbo.PARAM WITH (NOLOCK) ON dbo.SDSYSTXT.Sprache = dbo.PARAM.Sprache INNER JOIN
                         dbo.MVKARTEBEWEGUNG WITH (NOLOCK) ON dbo.MVKARTE.PhNr = dbo.MVKARTEBEWEGUNG.KartePhNr AND
                         dbo.MVKARTE.AnlageZtpkt = dbo.MVKARTEBEWEGUNG.KarteZtpkt AND dbo.MVKARTE.KartenNr = dbo.MVKARTEBEWEGUNG.KarteKartenNr INNER JOIN
                         dbo.SDSYSLAND WITH (NOLOCK) ON dbo.KUNDE.Landescode = dbo.SDSYSLAND.Landescode INNER JOIN
                         dbo.SDSYSLAND AS SDSYLAND_NATIONALITAET WITH (NOLOCK) ON dbo.KUNDE.Nationalitaet = SDSYLAND_NATIONALITAET.Landescode ON
                         SDSYSTXT_NATIONALITEAT.TxtCode = SDSYLAND_NATIONALITAET.BezTxtCode INNER JOIN
                         dbo.SDSYSABWEISUNG WITH (NOLOCK) ON dbo.MVKARTEBEWEGUNG.AbweisungsNr = dbo.SDSYSABWEISUNG.AbweisungsNr INNER JOIN
                         dbo.SDSYSTXT AS SDSYSTXT_ABWEISUNG WITH (NOLOCK) ON dbo.SDSYSABWEISUNG.TxtCodeLangTxt = SDSYSTXT_ABWEISUNG.TxtCode AND
                         dbo.PARAM.Sprache = SDSYSTXT_ABWEISUNG.Sprache INNER JOIN
                         dbo.SDSYSBEWEGUNG WITH (NOLOCK) ON dbo.MVKARTEBEWEGUNG.Bewegung = dbo.SDSYSBEWEGUNG.Bewegung INNER JOIN
                         dbo.SDSYSTXT AS SDSYSTXT_BEWEGUNG WITH (NOLOCK) ON dbo.SDSYSBEWEGUNG.BezTxtCode = SDSYSTXT_BEWEGUNG.TxtCode AND
                         dbo.PARAM.Sprache = SDSYSTXT_BEWEGUNG.Sprache INNER JOIN
                         dbo.ANLAGE WITH (NOLOCK) ON dbo.KUNDE.AnlagenNr = dbo.ANLAGE.AnlagenNr
WHERE        (dbo.MVKARTE.IstGeloescht = 0) AND (dbo.KUNDE.IstGeloescht = 0) AND (dbo.BENUTZER.IstGeloescht = 0) AND (dbo.MVKARTEBEWEGUNG.IstGeloescht = 0)
0
 

Author Comment

by:John-S Pretorius
ID: 39949256
To make it clear :- I created a SP 'Test' as below  which selects all columns from ContractParkerMovements (the View as described in my previous post) and I want to convert the Time column to a string so that I can see the milliseconds in Crystal reports - so far your convert seems adequate but I cannot seem to implement it properly in  my SP to keep everything ( ContractParkerMovements ) in tact and add the additional converted column.

ALTER PROCEDURE [dbo].[Test]
 
      -- Add the parameters for the stored procedure here
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

 select *  from dbo.ContractParkerMovements
 
END
0
 

Author Comment

by:John-S Pretorius
ID: 39949269
Thank you guys - The correct answer is :- (, *)

 select Convert(Varchar(24),ContractParkerMovements.Time,121) as strTime, *
from dbo.ContractParkerMovements
0
 

Author Comment

by:John-S Pretorius
ID: 39949295
I've requested that this question be closed as follows:

Accepted answer: 0 points for johnsp1234's comment #a39949269
Assisted answer: 150 points for IdoMillet's comment #a39948041
Assisted answer: 100 points for mlmcc's comment #a39948229

for the following reason:

Thank you - My apologies if I wasn't more clear
0
 
LVL 22

Expert Comment

by:Ido Millet
ID: 39949287
It is a bit strange that your definition of  "the correct answer" consists of the discovery that a comma separates columns and a * selects all columns in a SELECT statement.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 125 total points
ID: 39949291
Replace this

dbo.MVKARTEBEWEGUNG.Ztpkt AS Time,
with

Convert(Varchar(24),dbo.MVKARTEBEWEGUNG.Ztpkt, 121) as Time,

mlmcc
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now