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

  • SEARCH
  • Home
  • 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 6750529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:05+00:00 2026-05-26T12:49:05+00:00

I have table for comunication between clients and operaters, which contains phone, id (1=client,

  • 0

I have table for comunication between clients and operaters, which contains phone, id (1=client, 2=operater) date, message… and some other data.

I need to make stored procedure which will sort table like this

number1 operaters message
number1 clients message
number1 clients message
number1 operaters message
number1 *no message*
.
.
.

So, bassically, I need to find first message sent by operater and then client messages before next operaters message.
If after one operaters message there is no clients answer, I need to insert row like “no clients anwer” or something like that.

And that is large table, so will be good if it is less steps.

I know how to order by multiple columns, I know how to find first operaters message (select min time where id…) but I don’t know how to insert those rows where needed.

Thanks in advance for help.

And yeah, it’s MSSQL.

  • 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-26T12:49:06+00:00Added an answer on May 26, 2026 at 12:49 pm

    Didn’t actually test it, but this general idea should work:

    INSERT INTO YOUR_TABLE(NUMBER, DATE, USER_ID, MESSAGE)
    SELECT NUMBER, GETDATE(), 1, '*no message*'
    FROM YOUR_TABLE T1
    WHERE
        USER_ID = 2                       -- Operator.
        AND NOT EXISTS (
            SELECT *
            FROM YOUR_TABLE T2
            WHERE
                T1.NUMBER = T2.NUMBER
                AND T1.DATE <= T2.DATE
                AND USER_ID = 1           -- Client.
        )
    

    In plain English: for each operator message that does not have a younger client message, insert a new client message.

    (Based on your comment, USER_ID = 1 signifies a client and USER_ID = 2 operator.)

    Also note that using GETDATE()assumes all other dates are correct (i.e. none of them are in the future), implying that newly inserted message must be younger than its “parent” operator message. If that cannot be assumed, you’ll probably need to use DATEADD on operator message’s DATE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with some fields that the value will be 1 0. This
I have taken on a project from a client which requires me to set
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
i have table structure with 3 colums (column1, column2, column3) and i want to
I have table with 3 columns A B C. I want to select *
I have table with a unique auto-incremental primary key. Over time, entries may be
i have table unser it i have one td with elemets inside the menu
I have table in data base name train delay, with columns train number(int), DelayTime(int),

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.