Why does getdate() function return same time value for multiple select statements executed sequentially

When I run the following code
set nocount on
declare @i table(id int identity(1,1) primary key, sDate datetime)
while((select count(*) from @i)<10000)
begin
insert into @i(sDate) select getdate()
end
select top 5 sDate, count(id) selectCalls
from @i
group by sDate
order by count(id) desc
I get the following results. 
sDate                   selectCalls
2014-07-30 14:50:27.510 406
2014-07-30 14:50:27.527 274
2014-07-30 14:50:27.540 219
2014-07-30 14:50:27.557 195
2014-07-30 14:50:27.573 170
As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value.  This started happening when we moved our applications to a faster server with four processors.  Is this correct or am I
going crazy?
Please let me know
Bilal

Observe that adding 2 ms is accurate only with datetime2.  As noted above, datetime does not have ms resolution:
set nocount on
declare @d datetime, @i int, @d2 datetime2
select @d = getdate(), @i = 0, @d2 = sysdatetime()
while(@i<10)
begin
select @d2, @d, current_timestamp, getdate(), sysdatetime()
select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
end
2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
DATE/TIME functions:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Similar Messages

  • How to return the result set of multiple select statements as one result set?

    Hi All,
    I have multiple select statements in my stored procedure that I want to return as one result set 
    for instance 
    select id from tableA
    union 
    select name from table b 
    but union will not work because the result sets datatypes are not identical so how to go about this ?
    Thanks

    You have to CAST or CONVERT (or implicitly convert) the columns to the same datatype.  You must find a datatype that both columns can be converted to without error.  In your example I'm guessing id is an int and name is a varchar or nvarchar. 
    Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int.  If any row contains a row that has a value in name that cannot be converted to an int, you will get an error.  The solution is
    to force SQL to convert the int to varchar.  So you want something like
    select cast(id as varchar(12)) from tableA
    union
    select name from tableb
    If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
    Tom

  • Function returning cursor to be used in select statement

    I have written a function which returns a cursor. I want to use this in a select statement to display rows. How to do this.
    Eg : function - test_fn return sys_refcursor. (returns empno, empname, deptname)
    select test_fn from dual
    This should return
    empno empname deptno
    1 name1 dept1
    2 name 2 dept2
    ....

    Try This::
    SCOTT@xe_144>variable c  refcursor
    SCOTT@xe_144>CREATE OR REPLACE FUNCTION get_nm
      2     RETURN sys_refcursor
      3  AS
      4    
      5     c sys_refcursor;
      6  BEGIN
      7    
      8     open c for 'SELECT ENAME , SAL FROM EMP';
      9      
    10     RETURN c;
    11  END;
    12  /
    Function created.
    SCOTT@xe_144>select get_nm into :c from dual;
    GET_NM
    CURSOR STATEMENT : 1
    CURSOR STATEMENT : 1
    ENAME             SAL
    SMITH             800
    ALLEN            1600
    WARD             1250
    JONES            2975
    BLAKE            2850
    CLARK            2450
    KING             3000
    AKASH2           5000
    TURNER           1500
    ADAMS            1100
    JAMES             950
    MILLER           1300
    ABC              2000
    13 rows selected.Let me know if its works for you.

  • How do I return a true value for multiple expressions?

    Hi, I hope this question makes sense...
    In, for example, cell A1, I would like to return a True value when:
    C1>B1, and
    C2>B2, and
    C3>B3, and
    C4>B4, and
    C5>B5
    That is, if all column C values are greater than all corresponding column B values, then I would like to return a True value in cell A1.
    If one or more C values are less than or equal to their corresponding B values, e.g. B4<=C4, then I would like to return a False value in cell A1.
    Can this be achieved using a single formula in cell A1? If so what would that formula be?
    Thanks

    In column D I will insert the formula:
    =IF(OR(ISBLANK(B),ISBLANK(C)),"",IF(C>B,"",1))
    In A1 I will insert:
    =SUM(D)<0
    or
    in column D
    =IF(OR(ISBLANK(B),ISBLANK(C)),"",C>B)
    in A1
    =COUNTIF(D,FALSE)=0
    Yvan KOENIG (from FRANCE mardi 2 septembre 2008 12:11:28)

  • Setting property attribute values for multiple selected objects.

    Hello,
    Is there an easy way to set the attribute property values for more that one selected Table Operator Attribute (column) at a time. For example the target table has over 100 columns but I only want to INSERT/UPDATE 10 of those columns. The generated MERGE, INSERT and UPDATE statements will perform DML on all of the columns in the target table, setting the 90 columns with no mapping set to NULL. This is due to the Loading Properties 'Load Column when Updating Row' and 'Load Column when Inserting Row' both default to Yes. I would like to select multiple Attributes in the Table Operator and change the 'Load Column when Updating Row' and 'Load Column when Inserting Row' to No. This is similar to what you were able to do in Oracle Forms 9.0 Designer select multiple Items in a Block and change the properties en-masse.
    Thanks

    Hi,
    Using OMB scripting to set attribute properties in a data mapping sort of defeats the purpose of utilizing a graphical user interface to define and set properties for a data mapping? Surely the GUI data mapping tool was created to get away from writing scripts and scripting would also require that you know the name of the data mapping, table operator and the set of attribute names for which you have to write one line of script to set each property value, i.e. 90 lines to set 90 attribute values.
    Cheers,
    Phil

  • Display values for multiple selection

    In the code below, I am trying to display multiple values for Drop down list. when i run the code below the value "AA" is only selected on the screen but not BB.
    I want to display both AA and BB selected.
    Please any help/suggestions:
    <%@ page import="java.util.*"%>
    <jsp:useBean id="ab" class="com.a.b" scope="session"/>
    <select name="lstTyp" multiple>
    <%
    String Type[]= ab.getTyp();/*(VALUES ARE "AA-AA,BB-BB,CC-CC,DD-DD")*/
    String choiceType;
    String getTyp1 = "AA,BB";
    String getTyp = "";
    StringTokenizer parser = new StringTokenizer(getTyp1,",",false);     
              int numTokens = parser.countTokens();
              for(int j = 0; j <numTokens; j++)
                   getTyp = parser.nextToken();
                   for(int i=0; i<Type.length; i++)
                   {   choiceType = Type[i].substring(3);
                        if( getTyp.equalsIgnoreCase(Type.substring(0,2)) )
                             out.println("<option value=\"" + Type[i].substring(0,2) + "\" SELECTED >"+ choiceType );
                        else
                             out.println("<option value=\"" + Type[i].substring(0,2) + "\">"+ choiceType );
                   System.out.println(getTyp);
    %>
    </select>

    <select name="lstTyp" size="5" multiple>

  • On 64bit iOS 8.1 simulator, Why BOOL type function return a unexpected value?

    Code example:
    ------func.h------
    #import <Foundation/Foundation.h>
    @interface func : NSObject
    + (id)instance;
    @end
    ------func.m------
    #import "func.h"
    @implementation func
    + (id)instance
         static func *obj = nil;
         if (obj == nil) {
              obj = [func new];
         return obj;
    - (BOOL)test
         return YES;
    @end
    I created a new class "func" in project as above shown, set the project compile scheme to "release" mode.
    I found that if I call  [func test] method from another class, its return value is not "1" on iPhone6 simulator, it is a random value. Why?
    PS: I can not find this problem on iPhone6 device, it seems only happen on 64 bit simulator. Why?

    Your main problem as etresoft points out, is that your trying to use -test as a class method, you'll need to declare it as:
    +test { ... }
    for this to work. -test and +test are two different kinds of methods, -test needs a instance of 'func' to work:
    func *f = [[func alloc] init]; // create instance f of func
    [f test]; // calls -test, -test can use f as self
    while +test needs a class (name):
    [func test]; // calls +test
    Class methods are mainly used for creating/initiating instances of a class, the +init method is a typical example of this, other uses are are for utility methods that may not really be tied to a specific object (class instance). Also note that a class method doesn't have access to self as it wasn't called on an object, so data will need to be passed in via parameters or by using global variables.
    ===============
    dispatch_once() is the recommended way to do singletons, although the above will typically work assuming that its not accessed by multiple threads, e.g. is only used on the main thread.
    ===============
    This page http://www.bignerdranch.com/blog/bools-sharp-corners/ appears to relate to etrsofts dislike for BOOL (the standard boolean type of Objective-C) and his preference for bool (the C++ variant), but as the page mentions: "Update October 2013 - On 64-bit iOS (device and simulator) BOOL is now actually bool, so the sharp corners have thankfully gone away for that platform. For everything else, though…"

  • Why does iTunes display the same album art for different songs, but from the same artist?

    Hi,
    a couple of days ago I decided I wanted all of my songs to have an album art. Before I didn't actually care, but since I discovered the view mode with the album arts at the top (the fourth one) I began searching for the right arts, since I like it this way.
    I've stumbled upon a problem though. When I add two or more songs from the same artist, iTunes chooses to assign the same album art to the songs. It chooses the album art of the song I added first to my music library. How do I get it to show the proper album art?
    I use a program called 'Mp3Tag' to change all the information of my songs. When it's just a single, I end up having an 'artist', 'title', 'genre' and 'cover'. The rest of the information doesn't bother me. With albums I add more information though.
    Here's an example:
    I added two songs, one being 'Usher - Climax (Kaskade Remix)' and the other one being 'Usher - Scream'. The one added first was 'Scream'. As you can see below, iTunes somehow assigns the same album art to both songs, while clicking on 'get info' clearly shows the songs have different album arts.
    I discovered something else though:
    When adding an 'album name' to the songs, they will show properly, as seen below. The thing is though, I don't want to add an album name. When I sync the songs to my iPod, my 'albums' list will show all of the songs as well, which I don't want.
    Is there any way to solve this another way where iTunes won't sort by album, but by song title?
    Thanks in advance.

    Can anyone please answer my question?

  • Same sequence value for multiple targets

    Hello
    In my mapping, I have 4 target tables. The primary key of the first table is filled by a sequence. Now I should use the same value to fill in the 3 other tables.
    I was trying to use the sequence in the joiner and in the splitter but when I validate the mapping, I get the following error:
    "VLD-1800: Illegal use of sequence operator(s) in a complex mapping."
    How do I resolve this problem?
    Thank you for your answer.

    Hi
    A possible solution for your problem would be to populate your main table (Main_TL) with everything including the Sequence Number and have your other target a temporary table (Temp_TL) which has a common column (Natural Key) populated.
    Do another mapping joining the Main_TL and the temporary table (Temp_TL) using the Natural key joining condition and populate the remaining 3 targets to the output of the join.
    Hope this helps.
    Cheers,
    Sharad

  • Selection-screen - add default value to multiple selection

    Hi,
    How I can add a default value for multiple selection, on a Select-options?
    Thanks in advance,
    Brian Gonsales

    By default, selection optoins are RANGES, therefore to fill these before display, in the INITIALIZATION section
      CLEAR: so_field, so_field[].
      so_field = 'IEQvalue'. append so_field.
      so_field = 'IEQvalue2'. append so_field.
      so_field = 'IEQvalue3'. append so_field.
    If you want ranges
      CLEAR: so_field, so_field[].
      so_field = 'IBT'. so_field-low = 'lowvalue'. so_field-high = 'highvalue' append so_field.
    *  ETC
    Edited by: Paul Chapman on May 15, 2008 9:30 AM

  • Why does Muse crash practically every time I go to place an object?

    Why does Muse crash practically every time I go to place an object?

    Hello Zak. I am using Adobe Muse CC latest version on an iMac 7 running Yosemite version 10.
    I am placing a .jpg photo onto a page at the same size. Sized to fit I mean. This is happening about every 3 to 4 times I do something like asking to Place a file. It is driving be mad.
    I attach a screen grab of this all too familiar screen. I have updated to Air 3 also. What is going on, please help.
    Thanks.
    With kind regards, Richard
    Because good design is everyone's business.
    ROC Design Killough House, Killough Lower, Kilmacanogue, Bray, Co Wicklow.
    Call: 01 2762118 Email: [email protected] Skype: killoughhouse
    Web: http://www.rocdesign.ie

  • Why does my Adobe Reader installation time out?

    Why does my Adobe Reader installation time out at 64 percent on Windows XP?
    I am currently running version 9.5.2.
    Does anyone have a solution please.

    Hi,
    This "timeout at 64%" issue has been reported more than a few times  here.
    You can try direct download from
    http://get.adobe.com/reader/enterprise/
    If you can dedicate some time and help to investigate the issue, here is what I would ask:
    Before trying the link I have provided, can you please enable verbose MSI logging and try to install Reader the way you did originally - I assume that you used Adobe.com, right?
    If it fails again at 64%, please find the latest MSIxxxxx.log file in the Temp folder and send it to me.
    To enable Windows Installer logging
    http://support.microsoft.com/kb/223300
    ...open the registry with Regedit.exe and create the following path and keys: 
    HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer
    Reg_SZ: Logging
    Value: voicewarmupx
    The Temp folder on Windows XP is
    C:\Documents and Settings\[YourUserName]\Local Settings\Temp

  • Why does ipad has the same ios like the Iphone4s ,it should be different than iphonewhy does ipad has the same ios like the Iphone4s ,it should be different than iphone

    why does ipad has the same ios like the Iphone4s ,it should be different than iphone

    Having one iOS that works across several platforms is one of the advantages of the iOS system. This allows developers to produce one software product instead of several and reduces development time and costs. This is a fundamental difference between iOS and Android operating systems where operating system varieties impede development.

  • Can i play music and use mirroring function at same time from ipad2 to apple tv

    can i play music and use mirroring function at same time from ipad2 to apple tv

    Yes, any audio during the "mirroring" funtion will forward to the appletv. This includes all system audio, games, apps, ect. If you slide the mute botton the side of your ipad to mute then you can block app audio and just get Music audio or Pandora if you are using pandora.

  • Applet does not function the same.

    When I run my applet in IBM Visual Age it works fine. When I run it in my browser it does not function the same. It has to save a file on to my hardrive but it doesn't work. Can someone help.
    Thank you

    correction
    *hundreds of things*
    You gotta post some code, tell us what kind of error
    messages you're getting, or something. It could be
    dozens of things.

Maybe you are looking for

  • Qosmio F30 starts with blue stripes during the start screen of Vista

    My Qosmio F30-114 runs since years without Problems with Vista Ultimate. Since some Days there is a huge Problem. The Qosmio starts with blue stripes during the start screen of vista. So I deleted the driver of the graphic card and used the standard

  • Dates in APP - F110

    Hi All, Can any one please help me to clarify the following things: In case of APP Run in T.Code :F110” we find following fields: 1.     Posting Date 2.     Docs entered upto 3.     customer items due by 4.     Next P/Date What is purpose of each abo

  • How to implement this logic in odi

    suposse my table is like this a b c 1234 01-JAN-09 0 1234 02-JAN-09 1 1234 05-JAN-09 1 1244 06-JAN-09 1 1234 10-JAN-09 0 1234 13-JAN-09 1 1234 25-JAN-09 0 1234 27-JAN-09 1 1234 30-JAN-09 1 1235 01-JAN-09 1 1235 02-JAN-09 0 1235 05-JAN-09 1 1245 06-JA

  • Mountain Lion login screen background, how to change it?

    I've upgraded today, and while all other customizations still work just fine with Lion Designer 3 (updated), the login background is the only one that just won't work, not even manually. I'm stuck (again, as it was after the last Lion update) with th

  • Re-register / Enter Unlock Code Every Time PS Album is Launched

    Hi there, I have a client with Adobe Photoshop Album Starter Edition 3.2 bringing up the registration screen each time it's launched. The registration has been completed several times, and each time he did receive his unlock code. If you put the unlo