Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:49:32+00:00 2026-05-25T19:49:32+00:00

I have a SQL query like $result = mssql_query(INSERT into CALLER ( status, media,

  • 0

I have a SQL query like

$result = mssql_query("INSERT into CALLER
  ( status, media, media_2, first_name, last_name,  street_address, city,
  state, zipcode, home_phone_no, mobile_phone_no,email, problem, 
  medical_condition, comments,  updated_date )
  VALUES    
  ('CALL', '$media', '$media_2','$fname','$lname', '$street_addr', '$city',
  $state','$zip', '$phone_alt', '$phone','$email','$problem','$mc',
  '$comments',GetDate() ); ");

The primary key for the table CALLER is an auto-increment. How can I get the Primary Key of the row just inserted after this query ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:49:32+00:00Added an answer on May 25, 2026 at 7:49 pm

    Well if you have any CANDIDATE KEY in the table, you can use that to retrieve the last inserted row.

    Say you have a candidate key consisting of columns status, email and problem.

    Then you can execute a query like this just after your insert.

    $query = "SELECT id FROM CALLER 
              WHERE 
                   status = '" . $status . "' 
                   AND email = '" . $email . "' AND 
                   problem = '" . $problem . "'";
    mssql_query($query);
    

    This will return the id for that entry.

    Update
    I just saw this in a comment by Mikael to Femi’s Answer, you can use SCOPE_IDENTITY()

    It returns the las insert id for the current connection in current scope. So it should work for you even if multiple instances do inserts which are interleaved.

    So you can simply do this after the insert

    $res = mssql_query('SELECT SCOPE_IDENTITY()');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a result from an SQL query that I would like to sort
I have a simple SQL 'Select' query, and I'd like to dump the results
Right now, I have a SQL Query like this one: SELECT X, Y FROM
I have a SQL SELECT query which has a LIKE clause containing an underscore,
I have a problem that I would like have solved via a SQL query.
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I have the following code: public function createNewGuide($userID,$guideName) { $sql = INSERT INTO myTable(name,
I have a sql server query question. I have a table like below. Giving
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.