title: SQL query to extract pipe attributes to nodes via node id
body: <p>I have a GIS waternetwork where nodes are connected with 1 or more pipes. Each pipe has a node ID it starts in and finishes in (node IDs that are saved in the pipe table are node names and GlobalIDs).
  <a href="https://i.stack.imgur.com/yKw50.jpg" rel="nofollow noreferrer">GIS image on how the system can be connected is given in the attachment.</a></p>
  <p>I would like to run a query in SSMS that finds all pipes connected to a given node and returns categories of those pipes as a result. NB: I do not know if a given node is connected as a starting node or a finishing node of a pipe.</p>
  <p>I tried running following query, but it is extremely slow and I do not think it is logically correct.</p>
  <pre><code>SELECT s.GlobalId, s.TF_NODEID, s.NAME_NUMBER, s.REMARK, s.MAIN_FUNCTION, p.MAIN_FUNCTION
      FROM [WAT_NODE_evw] s
      LEFT JOIN [WAT_PIPE_evw] p ON s.NAME_NUMBER = p.START_NODE_1 OR s.NAME_NUMBER = p.START_NODE_2;
  </code></pre>
  <p><code>NAME_NUMBER</code> refers to a node name. <code>MAIN_FUNCTION</code> is the attribute I would like to extract for every pipe connected to a given node. Any suggestions on how I could do that?</p>