SQL CASE 语句

SQL CASE statement(SQL CASE 语句)
本文介绍了SQL CASE 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询,我想将它们放在 sql CASE 语句中,因此我只有一个查询,但我不知道该怎么做.有人可以帮我吗?

I have the following queries and I want to put them in an sql CASE statement so I would have only one query but I don't know how to do that. Can somebody help me?

IF (SELECT EtlLoadId 
 FROM  ssislogs.audit.processcontrol 
 WHERE SubjectArea = 'UaqaFacetsImp') > 0
SELECT pc.SrcFileName + ' - '+  CONVERT(VARCHAR(10), pc.[RecordCount] ) AS FacetsImpCount
 FROM  ssislogs.audit.processcontrol pc left outer join
 Uaqa.LettersAndCardsExports lc
on pc.etlloadid = lc.etlloadid
  WHERE pc.subjectarea = 'UaqaFacetsImp'
ELSE
SELECT 'No input file' AS FacetsImpCount

<小时>

SELECT pc.subjectarea AS FacetsRjctFile
FROM  ssislogs.audit.processcontrol pc left outer join
Uaqa.LettersAndCardsExports lc
on pc.etlloadid = lc.etlloadid
  WHERE pc.subjectarea = 'UaqaFacetsRjct'

<小时>

SELECT pc.subjectarea AS FacetsPvsFile
FROM  ssislogs.audit.processcontrol pc left outer join
Uaqa.LettersAndCardsExports lc
on pc.etlloadid = lc.etlloadid
  WHERE pc.subjectarea = 'UaqaFacetsPvs'

谢谢

推荐答案

UNION-Query 可能会有所帮助:

Propably a UNION-Query will help:

SELECT  'FacetsRjctFile' as Type, pc.subjectarea
FROM  ssislogs.audit.processcontrol pc left outer join
Uaqa.LettersAndCardsExports lc
on pc.etlloadid = lc.etlloadid
  WHERE pc.subjectarea = 'UaqaFacetsRjct'

UNION

SELECT 'FacetsPvsFile' as Type, pc.subjectarea
FROM  ssislogs.audit.processcontrol pc left outer join
Uaqa.LettersAndCardsExports lc
on pc.etlloadid = lc.etlloadid
  WHERE pc.subjectarea = 'UaqaFacetsPvs'

这篇关于SQL CASE 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)