Saturday, February 25, 2012

Data Manipulation

HI everyone,

I have a column STATUS of type bit(1,0) , i would like to manipulate it(without editing the database) in the Store Procedure in such a way that

if
STATUS =1 // return result STATUS= 'Active '
Else if
STATUS = 0 // return result STATUS = 'Inactive'
End if

My Stored Procedure Is As Follow

SELECT
STATUS + '--' + NAME AS STATUSNAME
FROM M_USER
END

Desired Result When Populated Into a Listbox Should Be As Follow

Active--Tester
Inactive--Tester1

Thanks In Advance for the Help Provided!

SELECT
CASE When Status = 1 Then 'Active'
ELSE 'Inactive'
END As STATUSNAME
FROM M_USER

:)

JB|||Thanks JBelthoff for the reply,

I follow ur example but its still not working , the code are as follow,

IF (@.MASTER = 'NRICSEARCH')
BEGIN
SELECT
CASE WHEN ACTIVE= 1 THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS ACTIVE,
USER_ID,
NRIC + '--' + NAME+ '(' + CONVERT(VARCHAR, ACTIVE) + ')' AS NRICNAME
FROM M_USER
ORDER BY NRIC

--
Column ACTIVE is of type bit.
NRICNAME is used in the listbox as datatextfield

TheCurrent Output from the current code in the listbox is as follow,

123--Ben(0)
124--Andy(1)

TheDesired Output in the listbox is as follow,

123--Ben(ACTIVE)
124--Andy(INACTIVE)

Apparantly, The CASE is not working.|||To get a 1 column result set in your desired output.......


SELECT CAST(USER_ID As Varchar) + '--' + NAME + '(' +
CASE
WHEN ACTIVE= 1 THEN 'ACTIVE'
ELSE 'INACTIVE'
END
+ ')' As NRICNAME
FROM M_USER

:-D

Enjoy!

JB|||Hi JB,

Its working now, thanks a lot.

No comments:

Post a Comment