SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to retrieve last inserted records
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

Abid
Posting Yak Master

Pakistan
109 Posts

Posted - 04/03/2013 :  21:36:26  Show Profile  Reply with Quote
I've inserted 9 records and when i check in SQL, so all have the same hour:minute: and second. I want to know that in what conditions the problem, you mentioned can be occured. Please guide me to put this code out of errors.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 04/04/2013 :  00:45:21  Show Profile  Reply with Quote
Don't worry about which one of your queries are best - you're most likely approaching it wrongly anyway.

How did you solve the insert problem?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=183810

The timestamp will be consistent if you inserted them all with the same timestamp explicitly established once and reused on each row. It won't work 100% if you insert rows one after the other and rely on many calls to get the date. (it might look like it, but it won't actually work close to milisecond boundaries).

So what did you do and why do you think a timestamp is a good idea? As soon as you get more than one user this whole thing is going to break on you. Create the concept of an insert batch table as I originally (and subsequently JamesK) recommended.

Go to Top of Page

Abid
Posting Yak Master

Pakistan
109 Posts

Posted - 04/04/2013 :  05:55:11  Show Profile  Reply with Quote
I think i've started same threads 2 times.
But in my few posts, before last one, i have mentioned that how i solved the problem, with change of query.

But anyways, Why I'm approaching all wrong? Lozt?
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/04/2013 :  11:07:15  Show Profile  Reply with Quote
Approach can be commented based on the business logic and we don't know what is the business logic behind your approach. Anyhow have you tried whatever so far suggested by the folks? If not yet try it first to see if you're getting what you looking for

Also, consider this example to see what issue you may face when you compare data just on the basis of a fix "Date" information

Declare @x int
set @x=0
declare @tab table (Col1 int, col2 datetime)
While @x<>300
Begin
insert into @tab values (1,GETDATE())
set @x=@x+1
end
Select distinct col2 from @tab

Say previously 300 records were added at once as a result of a transaction, having date as getdate(). but while saving all of them the date has differed a bit in miliseconds [depends on machine speed; on slower machine it would differ after every 10/20/30 etc records]. So if you are trying to pick information only on the basis of Max(Sale_date) it would come up and show partial information and not all of them.

However, if you're inserting the sale_date information to your table in following way

Declare @x int,@sale_date
set @x=0
set @sale_date =getdate()
declare @tab table (Col1 int, col2 datetime)
While @x<>300
Begin
insert into @tab values (1,@sale_date)
set @x=@x+1
end
Select distinct col2 from @tab

Only this way your date will be same for all records which were inserted in last insertion. And in this case the Max(Sale_Date) solution will work for you.
Hope this clarifies.

Cheers
MIK
Go to Top of Page

Abid
Posting Yak Master

Pakistan
109 Posts

Posted - 04/06/2013 :  05:41:26  Show Profile  Reply with Quote
@ MIK

I didn't understand the code you provided? Please guide me that what you want me to do.
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000