Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
johnguhan
Starting Member
10 Posts |
Posted - 2010-12-01 : 07:27:27
|
Hi, I wanna retrieve last inserted record where don't have auto Generated column.SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[InventoryItems]( [CompanyID] [nvarchar](36) NOT NULL, [DivisionID] [nvarchar](36) NOT NULL, [DepartmentID] [nvarchar](36) NOT NULL, [ItemID] [nvarchar](36) NOT NULL CONSTRAINT [pk_InventoryItems] PRIMARY KEY NONCLUSTERED ( [CompanyID] ASC, [DivisionID] ASC, [DepartmentID] ASC, [ItemID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]john guhan |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-01 : 07:30:37
|
Is there anything to order the rows by?If notthen you won't know the last inserted.Could maintain spmething using a trigger.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
gabling
Starting Member
6 Posts |
Posted - 2010-12-01 : 07:34:28
|
Is there any way to add an InventoryAdded datetime column? When a new item is added to the inventory, the date and time it is added would be included. A simple select statement with ranking would then be used to pull out the most recently added inventory item. |
 |
|
johnguhan
Starting Member
10 Posts |
Posted - 2010-12-01 : 10:25:17
|
In database Im using AuditTrail table that will store all users action that means insert,update and delete.so i dont want create column for datetime.john guhan |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-12-01 : 10:31:33
|
So you have not given all information that is needed to identify the last inserted record.We can't see your system... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-01 : 10:36:49
|
I take it you have the date of the action in the audit trail table?And the PK of the source table?You might need an index on the audit trail table but just use that.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
johnguhan
Starting Member
10 Posts |
Posted - 2010-12-01 : 21:36:53
|
Ur Correct...I ll try with AuditTrial Table...Thanksjohn guhan |
 |
|
|
|
|
|
|