sql server - How can I find the row in which error occurred while doing select with convert -
I am selecting the data from a table. The selection statement converts in seconds for the time. But it seems that there are invalid time values in the table and this is the reason to break the selection break. The statement below is:
Select (DATEPART (hH, duration) * 60 * 60) + (DATEPART (mile, duration) * 60) + Time Pert (ss, time) ) TimeInsecond
The error I get is:
My question: Do you know which row has the error? Is there any such facility in SDL server, such as ISDT that can validate time?
Will this work? If you want to see all the data, please see WHERE clause
Sample data:
IF OBJECT_ID (N'tempdb. # TEMP ') & Gt; 0 BEGIN Drop Table # TEMP Create End Table #TEMP (Table 1), VARCHAR (20), Duration VARCHAR (100), Fault Description VARCHAR (20)) Insert # TEMP values ('1', '2014-08-01 09: 38: 26.680 ',' right '), (' 2 ',' 2014-80-01 09: 38: 26.680 ',' wrong month '), (' 3 ',' 2014-08-100 09: 38: 26.680 ',' 'Wrong' ', (' 4 ',' 2014-08-01 09: 38: 90,80 ',' wrong time '), (' 5 ',' 2014-08-01 09: 38: 680 ',' Incorrect time format '), (' 6 ',' 2014-08-02 09: 08: 26.680 ',' right '), (' 7 ',' 2014-08-03 09: 39: 26.680 ', 'Right');
query:
select tableid, case when date (period) = 1 then ( DATEPART (HH, Duration) * 60 * 60) + (DATEPART (mi, A Dy) * 60) + DATEPART (SS, Duration) TimeIsec Second, Duration, Fault Description #TEMP WHERE ISDATE (Duration) = 1
Cleanup Script:
IF OBJECT_ID (N'tempdb .. # TEMP ') & gt; BEGIN drop table #TemP end
Comments
Post a Comment