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 8067249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:13:45+00:00 2026-06-05T12:13:45+00:00

I am working from 2 databases and I need to find records which matches

  • 0

I am working from 2 databases and I need to find records which matches the closest times. Both fields are datetime().

So in essence:

table1.time = 2012-06-07 15:30:00
table2.time = 2012-06-07 15:30:01
table2.time = 2012-06-07 15:30:02
table2.time = 2012-06-07 15:30:03

NOTE: The table I am querying (table2) is a mssql table, and table1.time is a datetime() time. I need to find in table2 the row which closest matches table1.time, but I have no guarnatee that it would be an exact match, so I need the closest. I only need to return 1 result.

I tried the SQL below based on an example from a previous stackoverflow query but it failed to work.

Table1 is a mysql database where table2 is mssql and the query happens on table2 (mssql)

  try {
            $sql = "
                SELECT     
                    PCO_AGENT.NAME, 
                    PCO_INBOUNDLOG.LOGIN AS LOGINID, 
                    PCO_INBOUNDLOG.PHONE AS CALLERID, 
                    PCO_INBOUNDLOG.STATION AS EXTEN, 
                    PCO_INBOUNDLOG.TALKTIME AS CALLLENGTH, 
                    PCO_INBOUNDLOG.CHANNELRECORDID AS RECORDINGID, 
                    PCO_SOFTPHONECALLLOG.RDATE, 
                    PCO_INBOUNDLOG.RDATE AS INBOUNDDATE
                FROM         
                    PCO_INBOUNDLOG 
                INNER JOIN
                      PCO_LOGINAGENT ON PCO_INBOUNDLOG.LOGIN = PCO_LOGINAGENT.LOGIN 
                INNER JOIN
                      PCO_SOFTPHONECALLLOG ON PCO_INBOUNDLOG.ID = PCO_SOFTPHONECALLLOG.CONTACTID 
                INNER JOIN
                      PCO_AGENT ON PCO_LOGINAGENT.AGENTID = PCO_AGENT.ID
                WHERE 
                    PCO_INBOUNDLOG.STATION = :extension
                AND ABS(DATEDIFF(:start,PCO_SOFTPHONECALLLOG.RDATE))
            ";
            $arr = array(":extension" => $array['extension'], ":start" => $array['start']);
            $query = $this->mssql->prepare($sql);
            $query->execute($arr);
            $row = $query->fetchAll(PDO::FETCH_ASSOC);
            $this->pre($row);
        }

I am getting the following error at the moment:

SQLSTATE[HY000]: General error: 174 General SQL Server error: Check messages from the SQL Server [174] (severity 15) [(null)]SQLSTATE[HY000]: General error: 174 General SQL Server error: Check messages from the SQL Server [174] (severity 15) [(null)]
  • 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-06-05T12:13:48+00:00Added an answer on June 5, 2026 at 12:13 pm

    Found a shorter version:

     SELECT * FROM `table` WHERE `date` < '$var' ORDER BY date LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a database from a legacy app which stores 24 floating
i'm working on an iPhone application which retrieve sqlite database from server through json/rest
I was working on a project which requires to download content from a database.
I'm working with a geographic point using lat/long and need to find other points
I need to find out what kind of database I am working against based
I'm working on app which saves things from many cross domains via Ajax POST
I am pulling (in the IT sense) hard drives from working machines and need
I want to display data from database in DataGridView...This is my code...Its not working...Can
I am working on porting over a database from a custom MSSQL CMS to
I am working with sqlite database. I retrieve text data from sqlite database into

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.