Transact SQL :: Lockout Time In Milliseconds
Dec 1, 2015why does select @@lock_timeout return -1. Shouldn't this return lock timeout in milliseconds?
View 2 Replieswhy does select @@lock_timeout return -1. Shouldn't this return lock timeout in milliseconds?
View 2 RepliesHi,
i am trying to add milliseconds to a time. For example if i have a time of 01:01:05:000 and i want to add 0.297 milliseconds to it i use the following simplified query
SELECT CONVERT(nvarchar(20), DATEADD(ms, 0.297, '00:01:05:000'), 14) AS Expr1
However instead of getting 01:01:05:0.297 i get 01:01:05:000. Can somebody please tell me what i am doing wrong.
Thanks in advance.
Hi,
i am trying to add milliseconds to a time. For example if i have a time of 01:01:05:000 and i want to add 0.297 milliseconds to it i use the following simplified query
Code:
SELECT CONVERT(nvarchar(20), DATEADD(ms, 0.297, '00:01:05:000'), 14) AS Expr1
However instead of getting 01:01:05:0.297 i get 01:01:05:000. Can somebody please tell me what i am doing wrong.
Thanks in advance.
I've been working on a project to ensure that accross our entire data warehouse everything is at the same accuracy level as far as time - migrating everything to use the full hh:mis.mmm. Some places were using hh:mis:mmm (colon instead of decimal point) and many places not using milliseconds.
The SQL server portion went essentially without issue - however SSIS is not cooperating. For example I have data I am importing from a file that is in format: hh:mis (no milliseconds) that I need to compare to data from SQL (now containing full milliseconds) - matching on time ranges. Previously this was done by converting both to the "database time" datatype in SSIS and comparing. Now when converting the cTime to database time SSIS fails and complains "The value could not be converted because of a potential loss of data".
I don't want to lop off the milliseconds becuase that could create rounding errors.
I don't like it but the only option I can think of is keeping everything in string and comparing the strings... then I run into the issue of making sure to convert all sources of data into the exact same hh:mis:mmm format in text.
Is there an easier way? I know some people use "milliseconds since midnight" and so forth but that would require major reworking of the data warehouse and many packages.
I need to set a variable to datetime and time to exact milliseconds in SQL server in stored procedure.
Example:
set MyUniqueNumber = 20071101190708733
ie. MyUniqueNumber contains yyyymmddhhminsecms
Please help, i tried the following:
1. SELECT CURRENT_TIMESTAMP; ////// shows up with - & : , I want single string as in above example.2.
select cast(datepart(YYYY,getdate()) as varchar(4))+cast(datepart(mm,getdate()) as char(2))+convert(varchar(2),datepart(dd,getdate()),101 )+cast(datepart(hh,getdate()) as char(2))+cast(datepart(mi,getdate()) as char(2))+cast(datepart(ss,getdate()) as char(2))+cast(datepart(ms,getdate()) as char(4))
This one doesnot display day correctly, it should show 01 but shows 1
I hope to update a DateTime column value with a Time input parameter.  Poor attempt below but it looks like the @ApptTime param is coming in as 10:45:00.0000000 and I might have an existing @SendOnDate as: 2015-10-05 07:00:00.000...I hope to end up with 2015-10-05 10:45:00.000
ALTER PROCEDURE [dbo].[SendEditUPDATE]
@QuePoolID int=null
,@ApptTime time(7)
,@SendOnDate datetime
[code]...
SELECTÂ
  CONVERT(VARCHAR(10),attnc_chkin_dt,101) as INDATE,
  CONVERT(VARCHAR(10),attnc_chkin_dt,108) as TimePart
FROM pmt_attendance
o/p
indate   04/18/2015
time part :17:45:00
I need to convert this 17:45:00 to 12 hours date format...
I have a custom application running against sql7 that has twice "locked up" sql7. The locked up symptom is that sql 7 will not allow any connections,
even from enterprise manager (server xxxxx is not responding........). The application returns an error that says the
"xxxxx" database is not available, using master instead. A look at the NT event log and the sql7 log provide no help. The OS is running fine and
existing connections (by the application) are still allowing database writes. How do trap what is causing sql7 to stop responding to connection
requests. I am presently starting and stopping the mssql service to get things running, but I really need a root cause. Any troubleshooting tips for
this would be greatly appreciated. Thanks in advance!
Can anyone tell me how a user gets lockedout in sql 2005. ?
View 4 Replies View RelatedHi,
I have been seeing a basic scenario of a write transaction appearing to unexpectedly lock-out reading.
The database has isolation set to "READ COMMITTED".
The scenario is:
1.) Start a transaction (for doing a write)
2.) Do a read before the transaction (for doing the write) is committed (e.g. sqlCommand2.ExecuteReader()).
--> the code will appear to lock-up (then time out).
I see the same behavior if I step through the "write" code with the debugger (to a point after the transaction is started, but before it is committed), and run a "SELECT * FROM" type query from Microsoft SqlServer Management Studio.
Following is the code sample demonstates the issue.
Thoughts on how to resolve the issue (to let me do "read committed" reading of the database table)?
Thanks!
Andy
Module Transaction
Sub Main()
Dim exception1 As Exception
Try
' Create/Open Database Connection
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Server=GRB-AB;Database=Transaction;Trusted_Connection=True;")
sqlConnection1.Open()
' Start transaction
Dim sqlTransaction1 As System.Data.SqlClient.SqlTransaction = sqlConnection1.BeginTransaction()
' Set Parent record
Dim sqlCommand1 As New System.Data.SqlClient.SqlCommand("INSERT INTO Parent (Name) VALUES ('ParentValue');", sqlConnection1)
sqlCommand1.Transaction = sqlTransaction1
sqlCommand1.ExecuteNonQuery()
' Get Id from parent record (note: this code assumes the table was empty when this program starts)
sqlCommand1 = New System.Data.SqlClient.SqlCommand("SELECT Id FROM Parent;", sqlConnection1)
sqlCommand1.Transaction = sqlTransaction1
Dim parentId As Integer = CType(sqlCommand1.ExecuteScalar(), Integer)
'
' Do reading test to test concurrently reading table being written to
'
' Create/Open Database Connection for reading test
Dim sqlConnection2 As New System.Data.SqlClient.SqlConnection("Server=GRB-AB;Database=Transaction;Trusted_Connection=True;")
sqlConnection2.Open()
Dim sqlCommand2 As New System.Data.SqlClient.SqlCommand("SELECT Id FROM Parent;", sqlConnection2)
sqlCommand2.ExecuteReader()
Dim i As Integer
While (sqlCommand2.ExecuteReader.Read = True) ' <===== LOCKS UP HERE **************
i = i + 1
End While
'
' End reading test
'
' Set child record
sqlCommand1 = New System.Data.SqlClient.SqlCommand( _
"INSERT INTO Child (Name, ParentId) VALUES ('ChildValue', " & parentId.ToString & ");", sqlConnection1)
sqlCommand1.Transaction = sqlTransaction1
sqlCommand1.ExecuteScalar()
' Either 1.) commit transaction OR 2.) rollback transaction
Dim test As Boolean = False
If test = False Then
sqlTransaction1.Commit()
Else
sqlTransaction1.Rollback()
End If
sqlConnection1.Close()
sqlConnection2.Close()
Catch ex As Exception
exception1 = ex
End Try
End Sub
End Module
I am running this code in a job:
EXEC msdb.[dbo].sp_send_dbmail
@profile_name = 'Blah Blah',
@recipients = 'blah@blah.com',
@subject = 'Server Report 1',
@body = '',
@execute_query_database = 'DBInfo',
@query = 'EXEC dbo.usp_SvrRpt1;',
@query_result_header = 0,
@query_result_width = 300,
--@attach_query_result_as_file = 1,
@query_result_separator = '';
GO
Because I am creating a total of 6 server reports, I alter the subject and query like so:
@subject = 'Server Report X' --where X is replaced with values 1 to 6
@query = 'EXEC dbo.usp_SvrRptX' --where X is replaced with values 1 to 6
I can run 4 reports without any problems. If I run more than 4 reports in the same batch, my network account under Windows 2000 Activity Directory is locked out as if I had erroneously mistyped my password the number of time to meet the lockout requirement - in this case, the number is 3 login tries.
Is this a known problem with Database Mail? If so, is there a fix or workaround?
Thanks,
Neal
Does SQL Server have any place to configure an account Lockout Threshold (SQL-authentication), also is there a default value (how many times failed logging would be initiated before the user lockout?)
View 7 Replies View RelatedI have the following code which returns day of week name, position and date and time of surgeries.
SELECT
DATENAME(WEEKDAY,OPE_START_TIME) AS DOW,
[OPE_ORDER_IN_SESS_ASC] AS POSITION,
OPE_START_TIME AS [TIME]
FROM table1The data looks like thisHow can i group this data so I get the average start time by day of week and position?
Hi
Does anybody know while loading data from text file into sql server, how
can we ignore milliseconds.
regards
JK
I have got data like this below in effective date column
2008-08-05 19:18:13.000
2008-08-05 19:17:10.000
Expected output:
2008-08-05 19:17:10
I need to truncate the milliseconds and insert the same into datetime column.
I tried as below
select convert(datetime,substring(convert(varchar,getdate(),20),1,20))
Thanks in advance
select TOP 10 rec_id,trans_id,number_id,card_no,message_id,trans_datetimefrom [dbo].[trans_log]
order by trans_datetime desc101, 1,34343, 99999, 200, 2015-11-23 12:27:25.710101,2,34343,99999,210,2015-11-23
12:27:26.710102,3,43434,88888,200,2015-11-23 12:28:26.714102,4,43434,88888,233,2015-11-23 12:28:27.710expected result:34343,99999,datediff(ss,'2015-11-23 12:27:26.710','2015-11-23 12:27:25.710') --difference between row 2 and row 143434,88888,datediff(ss,'2015-11-23 12:28:26.714','2015-11-23 12:28:27.710') --
difference between row 4 and row 3difference between row 6 and row 5...In the above query, I always want to find the difference in transaction date time between second and first row in a moving window.I have the unique id as rec_id to compare the next row with the previous row.
Table contains field defined as text. First 12 characters will be date format 'mm/dd/yyyy'. then the next 3 characters could be:
9A, 12P, 3P, 7A or LTL
I would like to convert '9A' to be 09:00AM, so that I can sort by that converted field.
'12P to be 12:00PMÂ Â Â and so on....
I have tried various form of case with substring and convert commands, but cant' get the solution. I can not change text field to varchar in table.
why the results I receiving for Seconds is different? I get the same MS results.
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Jun 28 2012 08:36:30
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
--Returns 1 second
SELECT RunTime_SEC = DATEDIFF(SECOND, '2015-02-09 13:34:13.977', '2015-02-09 13:34:14.230')
,RunTime_MS = DATEDIFF(ms, '2015-02-09 13:34:13.977', '2015-02-09 13:34:14.230')
--Returns 0 second
SELECT RunTime_SEC = DATEDIFF(SECOND, '2015-02-09 13:30:30.147', '2015-02-09 13:30:30.400')
,RunTime_MS = DATEDIFF(ms, '2015-02-09 13:30:30.147', '2015-02-09 13:30:30.400')
hi ppls..
we have sql server 2000 EM. we received daily xml files and we insert into our database.there is one column Date_T having data type datetime.till date we recieved this records from xml as '03/23/2004 12:23:34:956' but due to some duplicate isssue we now want to modified this column to recieve as milliseconds like '03/23/2004 12:23:34:956232' now my point is wheather sql server handle this kind of milliseconds..please help me out as early as possible..
T.I.A
Papillon
Hi!
I have the difference between two dates in milliseconds. I want to convert this difference to the format hh:mm:ss.mmm, without the date. So, if the difference is bigger then one day, I would like to show it like this, for example: 36:25:14.047
How can I do this?
Thank you!
Hi,
I am trying to access a date column up to millisecond precession. So I cast date to as follows:
Code BlockCONVERT(varchar(23),CREATE_DATE,121)
I get millisecond part as a result of query but it€™s €œ000€?.
I need to build a reference table that will contain the time zone, offset value and DST changes for all time zones. Is there a way I can pull this from the windows server hosting sql server?
View 4 Replies View RelatedI have a table like below
CREATE table #TempTable (ID integer,CTime time(7),CType Varchar(1))
insert into #TempTable VALUES (1001,'16:50:05.0000000','I')
insert into #TempTable VALUES (1001,'13:27:49.0000000','O')
insert into #TempTable VALUES (1001,'20:44:00.0000000','O')
insert into #TempTable VALUES (1001,'21:12:00.0000000','O')
I need result like below screen shotÂ
here 'I' stands for In,and 'O' for Out, in this example first In time not available
I am using aloha POS and they have the date for every check in separate fields and now I want to calculate the total time for the checks but unable to get the how of it..
The date is DOB and it's datetime but I just need to extra the getdate() from it.The open time is OPENHOUR and OPENMINThe close time is CLOSEHOUR and CLOSEMIN
so basically the open time for the check will be the DATE FROM DOB + OPENHOUR + OPENMIN
And the close time will be DATE FROM DOB + CLOSEHOUR + CLOSEMIN
How can I get the total minutes for the check?
Currently my script is using the below mentioned query to find the time difference.
DATEDIFF(HH,DATEADD(SS,hcreacion,fcreacion) ,DATEADD(SS,hcerrar,fcreacion))
If there is 1 hr 30 minutes time difference, I am getting 2 hours as output. But we need 1.30 as output. is there any way to achieve this?
I have the below query
DECLARE @GivenDate DATE='2015-05-13'
create table #table (LedgerID int,AttDate Date, checkedtime time,checkedtype varchar(1))
insert into #table (LedgerID,AttDate,checkedtime,checkedtype) values (1232,'2015-05-13','09:01:48.0000000','I')
insert into #table (LedgerID,AttDate,checkedtime,checkedtype) values (1232,'2015-05-13','13:05:52.0000000','O')
insert into #table (LedgerID,AttDate,checkedtime,checkedtype) values (1232,'2015-05-13','14:10:25.0000000','I')
[code]....
the result is like below
i need 'TotalDiffernceTime' column as new column (OUT1-IN1)+(OUT2-IN2).
i am using SQLServer 2008 R2
I have a table data like below
id     type    timestamp
1001Â Â Â start1Â Â Â 10:34:23:545
1001Â Â Â start2Â Â Â 10:34:24:545
1001Â Â Â end2Â Â Â 10:34:24:845
1001Â Â Â end1Â Â Â 10:34:25:545
1002Â Â Â start1Â Â Â 10:34:25:645
1002Â Â Â start2Â Â Â 10:34:25:745
1002Â Â Â end2Â Â Â 10:34:25:945
1002Â Â Â end1Â Â Â 10:34:25:965
I need the result as follows
id        millisecond diff start1end1               millisecond diff start2end2
1001   end1 timestamp-start1 timestamp   end2 timestamp-start2 timestamp
1002   end1 timestamp-start1 timestamp  end2 timestamp-start2 timestamp
SQL Server 2008 R2
We are maintaining 3 Shifts in our database. Problem in maintaining date and time for 3rd Shift. For example, today date is 13th July and third shift timing is 11 PM - 7 AM. Then I have to display the beginning date as 13/07/2015 11 PM and end date as 14/07/2015 7 AM. Please find the data(in seconds) available in database which I need to use for my calculation.
Date(Fcreacion)
Start time in Seconds(Hcreacion)
End time in seconds(Hcerrar)
turno(Shift)
[code]...
The first gives null (on sql 2014); the second works. why?
select format(cast('07:35' as time(0)), N'hh:mm')
select format(cast('07:35' as datetime2(0)), N'hh:mm')
I have a table Mytable which has two fields (Date, Value) and record is based on every hour like this:
Date Value
1999-01-01 00:00:00 10
1999-01-01 01:00:00Â 8
1999-01-01 02:00:00 6
...
1999-01-01 23:00:00Â 12
1999-01-02 00:00:00 9
1999-01-02 01:00:00 5
...
1999-01-02 23:00:00 2
How can I use a query to get accumulate value for the day? the result should look like this:
Date Value Accumulated_Value
1999-01-01 00:00:00 10 10
1999-01-01 01:00:00 8 18
1999-01-01 02:00:00 6Â 24...
1999-01-01 23:00:00Â 12 36
1999-01-02 00:00:00 9 9
1999-01-02 01:00:00 5 14...
1999-01-02 23:00:00Â 2 16
The accumulated value should be based on every hour for the day and then repeat for the second day and so on.
What is the best way to do this? I am using SQL 2008
i have these two tables
create table [dbo].[test1](
[test1_id] [int] identity(1,1) primary key,
[test2_id] [int] not null
)
[code]...
I want to insert the data into two tables in one insert statement. How can i do this using T-SQL ?
i have a table like below,
CREATE TABLE #ATTTABLE
(
Name VARCHAR(20),
AttDate DATE,
PresntTime TIME
[code]....
and then i pivot table by date as column wise using the below query and also displays total time by rowswise
SELECT t1.*, t2.Total
FROM (
SELECT Â name,[2015-08-01],[2015-08-02]
FROM (
SELECT Â name, AttDate,PresentTimeÂ
[code]....
now what i need is to display sum of time at last row as well, means total time of against date
I need a boost to understand how to get started on solving this SQL Query.
TicketId Seq StatusDateTime
T10001 1 2015-05-04 15:54:00.000
T10001 2 2015-05-04 16:35:00.000
T10001 3 2015-05-04 16:42:00.000
T10001 4 2015-05-05 08:19:00.000
T10002 1 2015-05-04 15:56:00.000
T10002 2 2015-05-04 15:57:00.000
I need to find the total StatusDateTime for each TicketId
I need to find the average StatusDateTime for all TicketIDs
Ex. TicketId, "T10001", has 4 records based on the Seq column.
By using this, I should be able to find the amount of time between the first Seq and the last Seq to get a total time span for Ticket.
Expanding on this, I should be able to add up all of the Ticket's calculated time spans and divide by the number of tickets to get the average time span.