views:

427

answers:

3
SELECT 
  PC_COMP_CODE,
  'R',
  PC_RESUB_REF,
  DECODE(PC_SL_LDGR_CODE,'02','DR','CR'),
  PC_DEPT_NO DEPT,
  '',--PC_DEPT_NO,
  PC_SL_LDGR_CODE+'/'+PC_SL_ACNO,
  SUM( DECODE(PC_SL_LDGR_CODE,'02',1,-1) *PC_AMOUNT),
  PC_CHEQUE_NO CHQNO
FROM GLAS_PDC_CHEQUES
WHERE PC_RESUB_REF IS NOT NULL AND PC_DISCD NOT IN ('d','D','T') 
GROUP BY PC_RESUB_REF, PC_COMP_CODE, 'JJ', PC_SL_LDGR_CODE+'/'+PC_SL_ACNO, PC_DEPT_NO, PC_CHEQUE_NO, DECODE(PC_SL_LDGR_CODE,'02','DR','CR')

Above is a Oracle query; how can I use DECODE() function in SQL Server 2005?

A: 

You can you CASE. See here

I am assuming you want to move the query from ORACLE to SQL Server ?

Preets
+3  A: 

If I understand the question correctly, you want the equivalent of decode but in T-SQL

Select YourFieldAliasName =
CASE PC_SL_LDGR_CODE
 WHEN '02' THEN 'DR'
 ELSE 'CR'
END
Andrew
+3  A: 

You could use the 'CASE .. WHEN .. THEN .. ELSE .. END' syntax in SQL.

daxsorbito