我有以下SQL查询
Declare @EIDDetail Table
(inc_synopsis varchar(5000),EmployeeName varChar(50),inc_id int, acc_id int
,acc_eid int, inc_event_Number Varchar(12), inc_date_occurred_startdate,acc_afg_id int,
inc_time_occurred_start varchar(8),inc_date_recvd date,inc_date_closed date,inc_is_uof bit,
InvestigatorName VarChar(42),inc_is_comp_via_sup bit,
inc_is_comp_via_psdbit, inc_is_admin_review bit
, inc_comp_is_inquiry bit, inc_comp_is_invest bit, div_name VarChar(50), inc_comp_is_referral bit)
INSERT INTO @EIDDetail SELECT b.inc_synopsis, a.EmployeeName As AccusedName, b.inc_id, a.acc_id, a.acc_eid,
b.inc_event_number, b.inc_date_occurred_start, a.acc_afg_id, b.inc_time_occurred_start, b.inc_date_recvd, b.inc_date_closed, b.inc_is_uof,
c.InvestigatorName, b.inc_is_comp_via_sup, b.inc_is_comp_via_psd,b.inc_is_admin_review,b.inc_comp_is_inquiry,b.inc_comp_is_invest, d.div_name,
b.inc_comp_is_referral
FROM dbo.VW_ACCUSED_DISCIPLINABLE_CHARGE AS a INNER JOIN
dbo.Tbl_Incident AS b ON a.acc_inc_id = b.inc_id LEFT OUTER JOIN
dbo.VW_INCIDENT_INVESTIGATOR AS c ON b.inc_id = c.inc_id LEFT OUTER JOIN
dbo.Tbl_Division AS d ON b.inc_inv_div_id = d.div_id
WHERE
a.acc_eid IN (435,35) And (b.inc_comp_is_inquiry = 'False') AND (b.inc_deleted = 'False') OR
a.acc_eid IN (435,35) And(b.inc_deleted = 'False') AND (b.inc_comp_is_invest = 'False') OR
a.acc_eid IN (435,35) And(b.inc_deleted = 'False') AND (b.inc_comp_is_referral = 'False') OR
a.acc_eid IN (435,35) And(b.inc_deleted = 'False') AND (b.inc_is_uof = 'True')
select * from @EIDDetail
这个工作正常,直到我有一个没有记录的参数。当发生这种情况时我需要包括由参数标识的员工并在记录集中显示员工姓名和"没有找到记录'在我的概要领域。
我似乎无法弄清楚这一点。我试过像这样使用ISNULL函数
SELECT ISNULL((SELECT My code above)), (new select here))
但是这给了我一条错误信息"当子查询没有用EXISTS引入时,只能在选择列表中指定一个表达式。"
我是否正在使用ISNUll功能朝着正确的方向前进?还是有其他方法可以实现这一目标
答案 0 :(得分:1)
我会做类似的事情:
DECLARE @EIDDetail Table <etc>
INSERT INTO @EIDDetail
SELECT <etc>
IF @@rowcount = 0
INSERT INTO @EIDDetail
SELECT <query designed for "no data available" parameters>
只是因为有可能将所有内容都塞进一个查询中(我对自己感到内疚)并不是一个好主意。
答案 1 :(得分:0)
如果要使用ISNULL表达式,则必须在该特定字段(而不是整个select语句)上使用它。所以,你可以有类似的东西:
extension Double {
func decomp () -> (mantissa:Int64,exponent:Int64) {
var (a,b) = frexp(self)
var exponent = Int64(b)
while floor(a) != a {
a *= 2
exponent--
}
let mantissa = Int64(floor(a))
return (mantissa, exponent)
}
}
以上假设Field1和field2是字符串类型(例如,Varchar)。
答案 2 :(得分:0)
然后,查询的输出应该是左连接或外部应用,其中主表是您传入的ID列表(以flex参数或表变量形式),因此:
apply plugin: 'com.android.library'
apply plugin: 'maven'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
}
dependencies {
compile 'com.google.dexmaker:dexmaker:1.2'
}
apply from: "${rootDir}/gradle/scripts/gradle-mvn-push.gradle"
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
pom.whenConfigured {
def dep = dependencies.find { it.groupId == 'com.google.dexmaker' }
dep.optional = true
dep.scope = null
}
}
}
}
}
然后,在报告方面,使您的输出响应第一次出现的&#34;无可用数据&#34;这样它就可以重新格式化输出。如上所述,请确保ISNULL的输出与您选择的列的类型相同。