---
title: "在sybase中使用case when"
author: "heyJoe"
date: "2009-07-02T09:50:26Z"
tags: ["Sybase"]
slug: "sybase-case-when"
draft: false
lastmod: "2009-07-02T09:50:26Z"
id: 418766
url: "https://heyjoe.iteye.com/blog/418766"
---

做外包的有时候真的很悲哀， sa一句设计变更， 我们的程序就得修改， 有时候修改的很少， 有时候修改的很多， 这次我就遇到了要修改全部程序的情况。言归正传， 在修改的过程中， 出现了这样的一个需求， 判断数据表中的某个字段是否为空，如果为空的话， 就修改表中的另一个字段， 如果大家奇怪为什么我要这样做， 我过后会把详细情况描述一下，但是现在先来温习温习case when的用法吧。

 

假设我们要根据数据表tempTable中的字段a是否为空来决定是否改变字段b的值，我们可以这样写

```
select t.a, 
          case when t.a is null then 'xxxx' 
          else t.b 
          end as b 
from tempTable t
```