Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Red face Unanswered: Insert multiple records for a single Id

    My project has a 'userid' as an identifier which needs to take a 'fromdate' and 'todate' many times to come up with a count. For example, if the user id is say '1', I need to be able to display like this:

    User Id:1

    1. Fromdate:_____ ToDate:___
    2. Fromdate:_____ ToDate:___
    3. Fromdate:_____ ToDate:___

    and finally, Count used: sums of (Todate-fromdate) off all 3 above


    User Id:2
    1. Fromdate:_____ ToDate:___
    2. Fromdate:_____ ToDate:___
    and finally, Count used : sums of (Todate-fromdate) off all 2 above

    UserId:3
    1. Fromdate:_____ ToDate:___
    2. Fromdate:_____ ToDate:___
    3. Fromdate:_____ ToDate:___
    4. Fromdate:_____ ToDate:___

    and finally Count used:sums of (Todate-fromdate) off all 4 above

    and so on..

    I have tried inserting using a regular insert statement but it would only work for the last 'fromdate' and 'todate' values. How do I insert multiple records for the single userid and yet not lose the old data?

    Any help would be really appreciated!!

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    lets see some code.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Mar 2010
    Posts
    3
    Well I'm not sure you can get this completely but here's the select query I came up with:

    SELECT User_Profile.MemFName, DATEDIFF(mm, User_Profile.DateOfHire, GETDATE()) AS RAWAccrual, DATEDIFF(mm, DATEADD(dd, DATEDIFF(dd, 0, User_Profile.DateOfHire), 0), DATEADD(dd, 14, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))) AS MidniteAccrual, DATEDIFF(dd, User_Holiday.ToDate, User_Holiday.FromDate) AS Duration, DATEDIFF(mm, DATEADD(dd, DATEDIFF(dd, 0, User_Profile.DateOfHire), 0), DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)) - DATEDIFF(dd, User_Holiday.ToDate, User_Holiday.FromDate) AS NetDays, User_Holiday.FromDate, User_Holiday.ToDate FROM User_Profile CROSS JOIN User_Holiday.

    I'm basically trying to display all the user related data into a webpage. It could be confusing- hence I just want to start freshly for this with a new database table.

  4. #4
    Join Date
    Mar 2010
    Posts
    3
    This query I showed just can store the last entered values if 'todate' and 'fromdate'. How do I instead store multiple values instead of just one for each userid?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •