如何在SQL Server 2005中解码 [英] How to decode in SQL Server 2005

查看:58
本文介绍了如何在SQL Server 2005中解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SQL Server的新手,所以这可能是一个非常简单的问题

来修复。我正在翻译Oracle查询,需要将

''解码'更改为兼容的东西。我读过的所有内容都指向我使用''case''
但是无论我怎么写它都不能让它工作并且

得到一个语法错误。建议?


选择SYST CTR

,isnull(substring(CD_A,1,3),'''')RESCODE

,DES描述

,解码(子串(CD_A,1,3),CODE,PRICE,0)UNIT_PRICE

,count(distinct OR_NO)QTYW

I am a novice to SQL Server, so this is probably a really easy problem
to fix. I''m translating an Oracle query and need to change the
''decode'' to something compatible. Everything I''ve read points me to
using ''case'' but no matter how I write it I can''t get it to work and
get a syntax error. Suggestions?

select SYST CTR
, isnull(substring(CD_A, 1, 3), '' '') RESCODE
, DES DESCRIPTION
, decode (substring(CD_A, 1, 3), CODE,PRICE,0) UNIT_PRICE
, count (distinct OR_NO) QTYW

推荐答案

da***@yahoo.com 写道:
da***@yahoo.com wrote:

我是SQL Server的新手,所以这可能是一个非常简单的问题

来修复。我正在翻译Oracle查询,需要将

''解码'更改为兼容的东西。我读过的所有内容都指向我使用''case''
但是无论我怎么写它都不能让它工作并且

得到一个语法错误。建议?


选择SYST CTR

,isnull(substring(CD_A,1,3),'''')RESCODE

,DES描述

,解码(子串(CD_A,1,3),CODE,PRICE,0)UNIT_PRICE

,count(distinct OR_NO)QTYW
I am a novice to SQL Server, so this is probably a really easy problem
to fix. I''m translating an Oracle query and need to change the
''decode'' to something compatible. Everything I''ve read points me to
using ''case'' but no matter how I write it I can''t get it to work and
get a syntax error. Suggestions?

select SYST CTR
, isnull(substring(CD_A, 1, 3), '' '') RESCODE
, DES DESCRIPTION
, decode (substring(CD_A, 1, 3), CODE,PRICE,0) UNIT_PRICE
, count (distinct OR_NO) QTYW



* googles(Oracle解码函数)*


选择SYST CTR

,isnull(substring (CD_A,1,3),'''')RESCODE

,DES描述

,案例子串(CD_A,1,3)

当CODE然后PRICE

否则0

结束UNIT_PRICE

,count(distinct OR_NO)QTYW

*googles (Oracle "decode function")*

select SYST CTR
, isnull(substring(CD_A, 1, 3), '' '') RESCODE
, DES DESCRIPTION
, case substring(CD_A, 1, 3)
when CODE then PRICE
else 0
end UNIT_PRICE
, count (distinct OR_NO) QTYW


选择SYST CTR
select SYST CTR

,isnull(substring(CD_A,1,3),''')RESCODE

,DES描述

,案例子串(CD_A,1,3)

*当CODE然后价格

*其他0

结束UNIT_PRICE

,count(不同的OR_NO)QTYW
, isnull(substring(CD_A, 1, 3), '' '') RESCODE
, DES DESCRIPTION
, case substring(CD_A, 1, 3)
* when CODE then PRICE
* else 0
end UNIT_PRICE
, count (distinct OR_NO) QTYW



谢谢。效果很好!

Thank you. That worked great!


Oracle现在也有CASE表达式。
Oracle now has the CASE expression, too.


这篇关于如何在SQL Server 2005中解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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