我有以下SQL查询:
<script type="text/javascript">
$(function(){
$("#MODAL_FORM").bind('ajax:success', function(event, data, status, xhr){
// Reset the Values
$('#MODAL_FORM input#email').val('');
// Let them know it was sent (Submit Button)
$('#MODAL_FORM #SEND_BUTTON').attr('value', 'Form Sent!');
// SET timeout to close the modal after above
// Does no have to be a timeout, this just lets the user
// See the text that it was sent, then closes it.
setTimeout(function(){
// Close the Window
$('#MODAL_FORM a.CLOSE_MODAL_LINK').click();
// OR
$('#modal').modal('toggle');
// OR
$('#modal').modal('hide');
// Reset the Submit Button Text
$('#MODAL_FORM #SEND_BUTTON').text('value', 'Send');
}, 500);
})
})
</script>
从1-10输出数字
我想我想在clock_pos上预先形成一个CASE语句
SELECT IIF(clock_to - clock_at_from < 0,
12 - (clock_at_from - clock_to),
clock_to - clock_at_from) AS clock_pos
FROM Condition
然后将最终结果作为条件表中的新列添加回来......
然而,我不确定如何使用名为clock_pos的结果或者如果有更好的方法来写这个。
@EDIT根据TONY Nested如果尝试。我无法再制作一个If语句
If clock_pos = 1 value = 3
If clock_pos = 2 value = 4
If clock_pos > 3 value = 5
答案 0 :(得分:1)
MS Access SQL实际上允许在同一查询中使用计算列:
SELECT IIF(clock_to - clock_at_from < 0,
12 - (clock_at_from - clock_to),
clock_to - clock_at_from) AS clock_pos,
IIF(clock_pos = 1, 3,
IIF(clock_pos = 2, 4,
IIF(clock_pos > 3, 5, NULL))) As clock_pos_value
FROM Condition
答案 1 :(得分:0)
如果使用子查询,将CASE
逻辑转换为嵌套IIF()
似乎很简单:
SELECT IIF(clock_pos = 1, 3
IIF(clock_pos = 2, 4,
IIF(clock_pos > 3, 5, NULL)
)
) as [value]
FROM (SELECT IIF(clock_to - clock_at_from < 0,
IIF(12 - (clock_at_from - clock_to) >= 3,
5, 12 - (clock_at_from - clock_to)
), clock_to - clock_at_from
) as clock_pos
FROM Conditions
) as c