1

I need to select the maximum value from a table , as described below , but do not return anything. I use PHP / SQL Server with library ADODB.

<?php
session_start();
//connessione al DB
include("dati_db.inc.php");
include ("init.php");
$qry = "select (IDSQL) from test.dbo.TTS_ext_ticket";
echo $qry;
$newrecordSet = $db->Execute($qry);
if ($db->ErrorMsg() != '') {    echo $db->ErrorMsg().' '.$condition; return;}

$ID_TICKET=$recordSet->fields["idticket"];
echo $ID_TICKET;   
?>
shA.t
  • 16,580
  • 5
  • 54
  • 111
  • 2
    You need MAX for MAX: `MAX(IDSQL)` and an alias too – Alex K. Jul 29 '15 at 16:48
  • possible duplicate of [SQL Server - Selecting a Record With MAX Value](http://stackoverflow.com/questions/8387587/sql-server-selecting-a-record-with-max-value) – Axel Guilmin Jul 29 '15 at 17:04

2 Answers2

1

Use MAX() Like :

$qry = "select MAX(IDSQL) AS max_idsql from test.dbo.TTS_ext_ticket";
callmemath
  • 8,185
  • 4
  • 37
  • 50
0

use this query

$qry = "select MAX(IDSQL) AS idticket from test.dbo.TTS_ext_ticket";

Note that the alias is named as idticket as this is what you expect later in code.

DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60