如何在CASE语句中不使用WHERE?

时间:2018-09-04 17:10:27

标签: sql sql-server

constructor(private loader: NgModuleFactoryLoader, private injector: Injector) {}

loadModule(path: string) {
    this.loader.load(path).then((moduleFactory: NgModuleFactory<any>) => {
        const entryComponent = (<any>moduleFactory.moduleType).entry;
        const moduleRef = moduleFactory.create(this.injector);
        const compFactory = moduleRef.componentFactoryResolver.resolveComponentFactory(entryComponent);
        this.lazyOutlet.createComponent(compFactory);
    });
}

有一个SELECT c.ClaimId, c.Number, s.ClaimStatusId StatusId, c.ClaimedAmount, c.Created AS Lodged, c.Updated, (u.UserName + '' + u.LastName) AS Creditor, c.JobId, j.CompanyName AS JobName, outcome.Approved AS ApprovedAmount, outcome.Rejected AS RejectedAmount, s.NormalizedName AS Status, type.Name AS Type, c.Version, c.RemarksCount FROM ClaimView c INNER JOIN ClaimType type ON c.TypeId = type.ClaimTypeId LEFT JOIN ClaimOutcome outcome ON outcome.ClaimId = c.ClaimId INNER JOIN Job j ON c.JobId = j.JobId INNER JOIN ApplicationUser u ON u.Id = c.CreatedBy INNER JOIN ClaimStatus s ON s.ClaimStatusId = c.StatusId WHERE c.CreatedBy = @userId AND c.StatusId > 1 AND c.IsDeleted = (CASE @isAdmin WHEN 'False' THEN 0 END) 变量,我需要使用@isAdmin IN(1,0)返回日期,或者根本不使用WHERE c。如果@isAdmin为True则完全删除Is.leted。我该如何实施?这就是我上面的当前代码。

3 个答案:

答案 0 :(得分:5)

embeddings_index = dict()
for word in model.wv.vocab:
    embeddings_index[word] = model.word_vec(word)
print('Loaded %s vectors' % len(embeddings_index))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-94-c1e5d21d49af> in <module>()
  1 embeddings_index = dict()
  2 for word in model.wv.vocab:
----> 3     embeddings_index[word] = model.word_vec(word)
  4 print('Loaded %s vectors' % len(embeddings_index))

AttributeError: 'Word2Vec' object has no attribute 'word_vec'

答案 1 :(得分:2)

您可以使用简单的OR

  • 可以检查@isAdmin不是false的事实(或者您可以/应该对照@isAdmin='true'进行检查)
  • c.isDeleted = 0

但是您不需要两个条件都成立。

...
WHERE 
c.CreatedBy = @userId 
AND c.StatusId > 1
AND (@isAdmin != 'False' OR c.IsDeleted = 0 )

答案 2 :(得分:1)

这应该做。可能有些矫kill过正,但我​​认为使用NULL处理在技术上也更合理:

    (
    AND (
        @isAdmin = 'False' 
    AND c.IsDeleted = 0
        )
     OR 
       (@isAdmin <> 'False'
    AND c.isDeleted IS NULL
       )
   )