TheFan1968 icon

Sybase-SQL case when clause

TheFan1968 | PRO | 07/13/16 09:25:42 AM UTC | 0 ⭐ | 220 👁️ | Never ⏰ | []
SQL |

910 B

|

None

|

0 👍

/

0 👎

DECLARE @current_bind VARCHAR(30)
SET @current_bind = 'tempdb_large_01'
DECLARE @set_tempdb VARCHAR(30)
SET @set_tempdb = 'blub'
 
CASE WHEN @current_bind='tempdb_large_01' THEN SET @set_tempdb = 'tempdb_large_02'
            WHEN @current_bind='tempdb_large_02' THEN SET @set_tempdb = 'tempdb_large_03'
            WHEN @current_bind='tempdb_large_03' THEN SET @set_tempdb = 'tempdb_large_01'
        ELSE SET @set_tempdb = 'blub'
        END
 
print 'current: %1! - set: %2!', @current_bind, @set_tempdb
GO
DECLARE @current_bind VARCHAR(30)
SET @current_bind = 'tempdb_large_01'
DECLARE @set_tempdb VARCHAR(30)
SET @set_tempdb = 'blub'
 
IF @current_bind='tempdb_large_01' BEGIN SET @set_tempdb = 'tempdb_large_02' END
IF @current_bind='tempdb_large_02' BEGIN SET @set_tempdb = 'tempdb_large_03' END
IF @current_bind='tempdb_large_03' BEGIN SET @set_tempdb = 'tempdb_large_01' END
 
print 'current: %1! - set: %2!', @current_bind, @set_tempdb
GO

Comments