在Where语句中使用字段值

时间:2018-05-08 01:51:41

标签: sql sql-server

我目前正在为数据库开发一些质量检查,我们有一个表格列出了哪些列是必填字段。我的问题是,是否可以使用此表生成where ... is null语句?以下示例

let totalCapacity = 500.0
// annotation collection property, used to store all annotations
let annotationGroup = SCIAnnotationCollection()

if (i%100 == 0){

        let customAnnotation = SCICustomAnnotation()
        let customAnnotationContentView = UILabel(frame: CGRect.init(x: 0, y: 0, width: 10, height: 10))
        customAnnotationContentView.text = "Y"
        customAnnotationContentView.backgroundColor = UIColor.lightGray

        customAnnotation.contentView = customAnnotationContentView
        customAnnotation.x1 = SCIGeneric(i)
        customAnnotation.y1 = SCIGeneric(0.5)
        customAnnotation.coordinateMode = .relativeY

        // adding new custom annotation into the annotationGroup property
        annotationGroup.add(customAnnotation)

        // removing annotations that are out of visible range
        let customAn = annotationGroup.item(at: 0) as! SCICustomAnnotation

        if(SCIGenericDouble(customAn.x1) < Double(i) - totalCapacity){
            // since the contentView is UIView element - we have to call removeFromSuperView method to remove it from screen
            customAn.contentView.removeFromSuperview()
            annotationGroup.remove(customAn)
        }

谢谢!

编辑:这是使用Microsoft SQL Server

更多详情: 我们有一个Transactions表,根据用户的类型(new,active,pending等),该表中的字段是否需要是不同的。我们有一个表格来映射这些要求(每个字段/状态组合的记录)。我希望使用该表格进行检查,以确保我们不会错过所需的信息。

1 个答案:

答案 0 :(得分:0)

我不确定我是否理解你的问题,但希望这会堆...你可以使用这个查询得到一个表的列表和所有可以为空的字段

select o.name TableName, c.name ColumnName
from sys.objects o
inner join sys.columns c on o.object_id = c.object_id
where c.is_nullable = 1 -- 1 for nullable, 0 for not nullable
and o.type = 'u' -- user table
and o.name = '{insert table name here if you wish to refine your search}'

从那里你可以借助游标

为每个表建立查询