Labels

Wednesday, April 3, 2013

Choose

-- CHOOSE() function will returns the value based on the specified index from the list of values.

DECLARE @Index INT,
        @FirstValue VARCHAR(10),
        @SecondValue VARCHAR(10),
        @ThirdValue VARCHAR(10)

SET @Index = 2
SET @FirstValue = 'One'
SET @SecondValue = 'Two'
SET @ThirdValue = 'Three'

SELECT CHOOSE (@Index, @FirstValue, @SecondValue, @ThirdValue)

SELECT * FROM [Person].[Address] ORDER BY CHOOSE (4 ,AddressLine1, AddressLine2, City, AddressID) -- Can Replace Dynamic SQL.

No comments:

Post a Comment