Guest User

Untitled

a guest
Aug 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. SQL join issue clarification
  2. SELECT cl.company
  3. FROM clients cl
  4. INNER JOIN supportstatus su
  5. ON cl.clientid = su.clientid
  6. WHERE su.agreement11 = 0
  7. AND su.status <> 'disabled'
  8. ORDER BY cl.company
  9.  
  10. <cfquery name="qryPendingAgreement" datasource="support">
  11. SELECT clientid
  12. FROM supportstatus
  13. WHERE agreement11 = 0 AND status <> 'disabled'
  14. </cfquery>
  15.  
  16. <cfquery name="qryClient" datasource="support">
  17. SELECT clientid, company, state, serv_billing
  18. FROM clients
  19. WHERE prod_arth = 1 OR prod_artr = 1 OR prod_epcr_host = 1 OR prod_epcr_remote = 1 OR prod_billing = 1 OR prod_collections = 1
  20. </cfquery>
  21.  
  22. <cfquery name="qryResults" dbtype="query">
  23. SELECT qryClient.company, qryClient.state, qryClient.serv_billing
  24. FROM qryPendingAgreement, qryClient
  25. WHERE qryPendingAgreement.clientid = qryClient.clientid
  26. order by qryClient.company
  27. </cfquery>
  28.  
  29. SELECT cl.company
  30. FROM clients cl
  31. INNER JOIN supportstatus su
  32. ON cl.clientid = su.clientid
  33. WHERE su.agreement11 = 0
  34. AND su.status <> 'disabled'
  35. OR prod_arth = 1 OR prod_artr = 1
  36. OR prod_epcr_host = 1 OR prod_epcr_remote = 1
  37. OR prod_billing = 1 OR prod_collections = 1
  38. ORDER BY cl.company
  39.  
  40. SELECT cl.company
  41. FROM clients cl
  42. INNER JOIN supportstatus su
  43. ON cl.clientid = su.clientid
  44. WHERE su.agreement11 = 0
  45. AND su.status <> 'disabled'
  46. AND ( prod_arth = 1 OR prod_artr = 1
  47. OR prod_epcr_host = 1 OR prod_epcr_remote = 1
  48. OR prod_billing = 1 OR prod_collections = 1
  49. )
  50. ORDER BY cl.company
  51.  
  52. WHERE su.agreement11 = 0
  53. AND isnull(su.status,'') <> 'disabled'
  54.  
  55. DECLARE @client TABLE
  56. (
  57. clientid int,
  58. company VARCHAR(50)
  59. )
  60. DECLARE @supportstatus TABLE
  61. (
  62. clientid int,
  63. [status] VARCHAR(50),
  64. agreement INT
  65. )
  66.  
  67. INSERT INTO @client ([clientid],[company]) VALUES ( 0,'acme' )
  68. INSERT INTO @client ([clientid],[company]) VALUES ( 1,'byron' )
  69. INSERT INTO @client ([clientid],[company]) VALUES ( 2,'cathode' )
  70.  
  71. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'disabled',0)
  72. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'disabled',1)
  73. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'somethingelse',0)
  74. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'somethingelse',1)
  75.  
  76. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'disabled',0)
  77. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'disabled',1)
  78. --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'somethingelse',0)
  79. --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'somethingelse',1)
  80.  
  81. --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'disabled',0)
  82. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'disabled',1)
  83. --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'somethingelse',0)
  84. INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'somethingelse',1)
  85.  
  86. -- all companies who have su.agreement = 0 and su.status <> 'disabled'
  87. SELECT cl.company
  88. FROM @client cl
  89. JOIN @supportstatus su ON cl.clientid = su.clientid
  90. WHERE su.agreement = 0 AND su.status <> 'disabled'
  91. Order By cl.company
Add Comment
Please, Sign In to add comment