MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 10th, 2008, 10:31 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Question Returning Last Entire Row of MSSQL DB

I know this solution has to be easy but I can not find many references to it on the Internet or through any MSSQL or PHP help.

I am coding a form through PHP using an MSSQL db. I linked the form to a submit.php where the data is written into the database and that works fine; however, after the data is written I would like to use an SQL Query to output the entire last row of data (that was just written in). I know I could use the text box names, but I have a few hidden fields that don't get their data from any text area on the previous page. I do have a unqiue autoincrement number so I'm guessing I could do some type of a query and only display the highest number but I have no idea how to go about it.

Any help would be great! Thanks.

Reply With Quote
  #2  
Old July 10th, 2008, 11:57 AM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,009 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 14 h 5 m 37 sec
Reputation Power: 67
If your table does not have a primary key, you should really re-thinkg your DB model.

Reply With Quote
  #3  
Old July 10th, 2008, 12:15 PM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by shammat
If your table does not have a primary key, you should really re-thinkg your DB model.


The primary key is my unique generated number. I apologize I did not specify this, I wasn't sure it would make a difference in the question. Thanks for the reply!

Reply With Quote
  #4  
Old July 10th, 2008, 12:18 PM
f'lar's Avatar
f'lar f'lar is offline
Senior WeyrLeader
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 3,897 f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 5 Days 10 h 32 m 56 sec
Reputation Power: 800
Send a message via Google Talk to f'lar
Add a timestamp column to the table, and just select back the row with the biggest timestamp.
__________________
Primary Forums: .Net Development, MS-SQL, C Programming
VB.Net: It's not your father's Visual Basic.

[Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

Reply With Quote
  #5  
Old July 10th, 2008, 12:39 PM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by f'lar
Add a timestamp column to the table, and just select back the row with the biggest timestamp.


I should have stated this earlier, I am a sql noob. I know very little and what I do know, I'm learning out of books.

I do, of course, know how to add a timestamp column, but then how would I go back to the biggest one and then output that onto my PHP page?

Thanks for the help again guys, I appreciate it.

Reply With Quote
  #6  
Old July 10th, 2008, 01:12 PM
f'lar's Avatar
f'lar f'lar is offline
Senior WeyrLeader
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 3,897 f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level)f'lar User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 5 Days 10 h 32 m 56 sec
Reputation Power: 800
Send a message via Google Talk to f'lar
SELECT TOP 1 * FROM [MyTable] ORDER BY [MyTimestampColumn] DESC

Reply With Quote
  #7  
Old July 10th, 2008, 01:21 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,965 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 16 h 55 m 24 sec
Reputation Power: 1024
Quote:
Originally Posted by f'lar
Add a timestamp column to the table, and just select back the row with the biggest timestamp.
nooooooooooo!!!

obviously you've never worked in a multi-threaded environment...



fleppar, look up the SCOPE_IDENTITY function in your manual
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Returning Last Entire Row of MSSQL DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT