执行SQL语句以防万一 [英] Executing SQL Statement in Case When Then

查看:66
本文介绍了执行SQL语句以防万一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Select
Case
When
(Select Count(ID) From TaskAssignment where BookCode='CCITAY09' and Section='w01')
 =
(Select Count(ID) From TaskAssignment where BookCode='CCITAY09' and Section='w01' and Status='Completed')
then
Begin
    Select Max(EndTime) EndTime From
    (
    Select EndTime From AssignedTaskReporting where BookID in
    ( Select ID From TaskAssignment where BookCode='CCITAY09' and Section='w01' )
    and EndTime !='N/A'
    union all
    Select EndTime from WLATaskAssignment where BookID='CCITAY09' and Section='w01' and Status='Completed'
    )v
End
else
'hlkljhlj'
--begin
--'' EndTime
End

推荐答案

在条件之前添加IF语句
喜欢

Add a IF Statement before the condition
like

if (Select
Case
When
(Select Count(ID) From TaskAssignment where BookCode='CCITAY09' and Section='w01'))
 =
(Select Count(ID) From TaskAssignment where BookCode='CCITAY09' and Section='w01' and Status='Completed')

Begin
    Select Max(EndTime) EndTime From
    (
    Select EndTime From AssignedTaskReporting where BookID in
    ( Select ID From TaskAssignment where BookCode='CCITAY09' and Section='w01' )
    and EndTime !='N/A'
    union all
    Select EndTime from WLATaskAssignment where BookID='CCITAY09' and Section='w01' and Status='Completed'
    )v
End
else
'hlkljhlj'
--begin
--'' EndTimeEnd
END


这篇关于执行SQL语句以防万一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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