Skip to content
Advertisement

Look up in same table with different value reference sql server [closed]

I’d like some help with a code. I have TableA where Btime is sometimes 0.

I need to get from the same table the value of Btime where Dest, Orig and Bcode are the same as in the row where Btime is 0 and convert Btime to HH:MM:SS

The result would be:

How can I get this for my entire table if there are multiple values that can meet this condition?

Version is Microsoft SQL Server 2017 (RTM) – 14.0.1000.169 (X64)

Advertisement

Answer

You can convert the values to a time for the format and use window functions to fill in the value:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement