NULL值未返回

时间:2016-03-17 20:31:30

标签: sql sql-server

我遇到的情况是我再次运行查询表MEMBERS,MEMBERUDFS和MEMERUDFSETUPS。 MEMBER UDF是用户定义字段,由系统管理员创建,用于在可自定义字段中存储有关客户的数据。 UDFSETUPS表定义可配置字段,MEMBERUDFS存储这些字段的值(如果存在)。

我遇到的问题是当我拉回数据时,我没有获得具有ID为17的UDF(MEMBERUDFS.udfid =' 17')的条目的行有条目或为空。我尝试过Left Joins,但似乎没什么帮助。

SELECT MEMBERS.scancode, MEMBERS.fname, MEMBERS.lname, MEMBERS.datejoin, MEMBERS.entrydate
     , MEMBERS.relationship, MEMBERUDFS.udfvalue
FROM MEMBERS 
LEFT OUTER JOINMEMBERUDFS 
  ON MEMBERS.memid = MEMBERUDFS.memid 
INNER JOIN MEMBERUDFSETUPS 
  ON MEMBERUDFS.udfid = MEMBERUDFSETUPS.udfid
WHERE (MEMBERS.siteid = @rvSite) 
  AND (MEMBERS.status = 'A') 
  AND (MEMBERS.relationship = 'M') 
  AND (MEMBERUDFS.udfid = '17') 
  AND (MEMBERS.datejoin BETWEEN @rvStartDate AND @rvEndDate) 
  AND (MEMBERS.mtypeid NOT IN (5, 6, 7, 11, 14, 31)) 
   OR (MEMBERS.siteid = @rvSite) 
  AND (MEMBERS.relationship = 'P') 
  AND (MEMBERUDFS.udfid = '17') 
  AND (MEMBERS.entrydate BETWEEN @rvStartDate AND @rvEndDate)

1 个答案:

答案 0 :(得分:2)

将JoinMemberUDFS的限制移动到连接,或者排除空值。

首选方法移动过滤器以加入条件

with

当它为空时不是首选句柄并确保它为评估返回true

import os

name = "Test" # I had to come up with something
class_number = input("Please enter your class: ")
score = input("Please enter your score: ")

folder = "Class" + class_number
file_name = name + ".txt"
path = os.path.join(folder, file_name)
if os.path.exists(path):
    print("File found")
else:
    print("File not found. Creating file")

with open(path, "a") as txt_file:
    txt_file.write(score + "\n")