Click here to Skip to main content
15,887,027 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQLite syntax error that I can't figure out Pin
k50544-Nov-23 17:22
mvek50544-Nov-23 17:22 
GeneralRe: SQLite syntax error that I can't figure out Pin
Richard Andrew x645-Nov-23 1:57
professionalRichard Andrew x645-Nov-23 1:57 
Questionplease Pin
daw htikehtike21-Oct-23 19:17
daw htikehtike21-Oct-23 19:17 
AnswerRe: please Pin
Richard MacCutchan21-Oct-23 21:14
mveRichard MacCutchan21-Oct-23 21:14 
AnswerRe: please Pin
jschell23-Oct-23 5:25
jschell23-Oct-23 5:25 
AnswerRe: please Pin
Gerry Schmitz24-Oct-23 7:15
mveGerry Schmitz24-Oct-23 7:15 
AnswerRe: please Pin
CHill6029-Oct-23 23:44
mveCHill6029-Oct-23 23:44 
QuestionGetting Last Record and First Record from a Record Set (SQL server DB) Pin
Member 1184335621-Sep-23 8:07
Member 1184335621-Sep-23 8:07 
I am pretty new using MS SQL. I perform a query over some SQL server table; it returns a record set; but I need to read the last record just to get the value of a certain column.

This is my procedure:
PHP
$connectionInfo = array( "Database"=>$myDB, "UID"=>$myUser , "PWD"=>$myPass);
$conn = sqlsrv_connect( $myServer, $connectionInfo);

$query = "SELECT * FROM( SELECT col0, col1, col2, col3 FROM t1 LEFT JOIN t2 ON t1.col1 = t2.col1 LEFT JOIN t3 ON t1.col2 = t3.col2) AS t ORDER BY t.col0; ";
$rec_set = sqlsrv_query($connection, $query, array(), array("Scrollable" => 'buffered'));

if( $rec_set === false ) die( print_r( sqlsrv_errors(), true));  

$connectionInfo = array( "Database"=>$myDB,  UID"=>$myUser , "PWD"=>$myPass);
$conn = sqlsrv_connect( $myServer, connectionInfo);

$query = "SELECT * FROM( SELECT col0, col1, col2, col3 FROM t1 LEFT JOIN t2 ON t1.col1 = t2.col1 LEFT JOIN t3 ON t1.col2 = t3.col2) AS t ORDER BY t.col0; ";

$rec_set = sqlsrv_query($connection, $query, array(),  array("Scrollable" => 'buffered'));
if( $rec_set === false ) die( print_r( sqlsrv_errors(), true));	
			 
$row_count = sqlsrv_num_rows($rec_set);
if ($row_count === false) die( print_r( sqlsrv_errors(), true));

$reg   = sqlsrv_fetch_array( $rec_set, SQLSRV_FETCH_ASSOC, 0);
$first = $reg['column_name'];

$reg   = sqlsrv_fetch_array( $rec_set, SQLSRV_FETCH_ASSOC, $row_count - 1);
$last  = $reg['column_name'];


It is clear that the sqlsrv_fetch_array DOES NOT work like that. Does anyone know how to achieve my goal, that is, getting last and first records from that record set without generating another SELECT?
Thank you in advance.
AnswerRe: Getting Last Record and First Record from a Record Set (SQL server DB) Pin
Richard Andrew x6421-Sep-23 8:58
professionalRichard Andrew x6421-Sep-23 8:58 
GeneralRe: Getting Last Record and First Record from a Record Set (SQL server DB) Pin
Member 1184335621-Sep-23 9:18
Member 1184335621-Sep-23 9:18 
GeneralRe: Getting Last Record and First Record from a Record Set (SQL server DB) Pin
Gerry Schmitz21-Sep-23 14:02
mveGerry Schmitz21-Sep-23 14:02 
Questionprior action plan to prevent sql database corruption Pin
Kar_Malay1-Sep-23 20:01
Kar_Malay1-Sep-23 20:01 
AnswerRe: prior action plan to prevent sql database corruption Pin
Richard Andrew x642-Sep-23 2:38
professionalRichard Andrew x642-Sep-23 2:38 
GeneralRe: prior action plan to prevent sql database corruption Pin
Dave Kreskowiak2-Sep-23 3:33
mveDave Kreskowiak2-Sep-23 3:33 
AnswerRe: prior action plan to prevent sql database corruption Pin
jschell4-Sep-23 5:42
jschell4-Sep-23 5:42 
GeneralRe: prior action plan to prevent sql database corruption Pin
Kar_Malay2-Oct-23 9:22
Kar_Malay2-Oct-23 9:22 
QuestionFetch row and display in frontend column Pin
Kesiena26-Aug-23 3:14
Kesiena26-Aug-23 3:14 
AnswerRe: Fetch row and display in frontend column Pin
David Mujica28-Aug-23 3:16
David Mujica28-Aug-23 3:16 
AnswerRe: Fetch row and display in frontend column Pin
jschell29-Aug-23 5:01
jschell29-Aug-23 5:01 
AnswerRe: Fetch row and display in frontend column Pin
Rohan Saadat17-Nov-23 5:10
Rohan Saadat17-Nov-23 5:10 
QuestionMulti-user use the database at the same time Pin
Siavash.BRY11-Aug-23 23:49
Siavash.BRY11-Aug-23 23:49 
AnswerRe: Multi-user use the database at the same time Pin
Richard Deeming13-Aug-23 21:18
mveRichard Deeming13-Aug-23 21:18 
AnswerRe: Multi-user use the database at the same time Pin
Dave Kreskowiak14-Aug-23 5:12
mveDave Kreskowiak14-Aug-23 5:12 
AnswerRe: Multi-user use the database at the same time Pin
jschell14-Aug-23 6:37
jschell14-Aug-23 6:37 
QuestionTough one Pin
Richard Andrew x6431-Jul-23 4:59
professionalRichard Andrew x6431-Jul-23 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.