计算列 - 需要帮助写作语句 [英] Computed Column - Need help writing statement

查看:83
本文介绍了计算列 - 需要帮助写作语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从未听说过计算列,直到我需要设置一个今天,所以请原谅愚蠢。这是我的create table语句

Never heard of computed column until I needed to set one up today so excuse the stupidity. Here is my create table statement

CREATE TABLE [Match](

    [Match Org] [nvarchar](10) NULL,
    [Bypass] [nvarchar](10) NULL,
    [win] as case when [Match Org] == 'yes' or [Bypass] == 'yes' then 'yes' else 'no'

) ON [PRIMARY]

GO

$ b b

我想要win列自动计算为yes如果匹配org或bypass在它们中有yes ...感谢

I want the win column to automatically compute to yes if either match org or bypass have yes in them... thanks

推荐答案

CREATE TABLE [Match](

    [Match Org] [nvarchar](10) NULL,
    [Bypass] [nvarchar](10) NULL,
    [win] AS CASE WHEN  ( [Match Org] = 'yes'    --- equality check is:  =
                       OR [Bypass] = 'yes' )     --- not:  ==
                  THEN 'yes' 
                  ELSE 'no'
             END                                 --- END was missing
        PERSISTED             --- you may also want to make
                              --- the column PERSISTED 
) ON [PRIMARY]

这篇关于计算列 - 需要帮助写作语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆