1

Below table displays package transferred from origin to destination.

[![enter image description here][1]][1]

Explanation:

  1. Sent America 2022-11-23 18:30:00.000 Reached China 2022-11-24 05:00:00
  2. Sent China 2022-11-24 08:18:00.000 Reached Argentina 2022-11-24 18:18:00.000
  3. Sent Argentina 2022-11-25 18:30:00.000 and reached Saudi Arabia 2022-11-25 20:30:00.000
6
  • Why do you need double number for seqNo? I'd use a regular integers; 1, 2, 3 etc. Commented Nov 24, 2022 at 10:13
  • 1
    Hint: self join. Commented Nov 24, 2022 at 10:14
  • @jarlh Primary focus is on the ContryFrom , CountryTo and Remarks. . SeqNo with intergers 1,2,3,4,5 is also okay. Commented Nov 24, 2022 at 10:15
  • @jarlh I am trying using self join but since I'm not at all good in queries so facing issues. I'd appreciate your help. Commented Nov 24, 2022 at 10:24
  • Self join is not anough as you need one self join for every node on a multi-path route. What you are looking for is a recursive query. See, for example, stackoverflow.com/questions/20215744/… Commented Nov 24, 2022 at 10:58

1 Answer 1

3

I hope the below answer is suitable for you.

less than <

select  f.id,f.Country CountryFrom, t.Country CountryTo
, convert(varchar(4),f.seqNo) + '-' + convert(varchar(4),t.seqNo) seqNo
, f.Send, t.Arrive,concat('Send ', f.Country ,' ', f.Send,' Reached ', t.Country,' ',t.Arrive) Remarks from IPhone f inner join IPhone t on f.seqNo < t.seqNo order by id;

Thanking you

Sign up to request clarification or add additional context in comments.

4 Comments

Beautifully done. . Thank you so much Sirji. Apka bahut bahut dhanyawad.
Note that this will work if you don't need the remarks part, because all information is available in the self join. If you need the "via" information from the Remarks column shown in the question, you need a recursive query.
Yes, but the requirement is to populate the remarks only if there is VIA otherwise keep it blank. I think I need to use the recursive anyway.
@StefanWinkler Can you please help me in the recursive section please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.