Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using below code getting details of customer who paid cash and who paid using card,
using this i can show whether its cash or card. but client need if card then need to show card no and bank name., i am getting struck here please help me out., thanx in advance.,



SQL
DELCARE @TEMPTABLE TABLE
(
CUSNAME NVARCHAR(450),
PAYMENT_MODE nvarchar(250),
CARDNO nvarchar(450),
BANKNAME nvarchar(450),
)

INSERT INTO @TEMPTABLE
(
CUSNAME,PAYMENT_MODE,CARDNO,BANKNAME
)

SELECT CUSNAME,

CASE (PAYMENTMODE)
WHEN 1 THEN 'CASH'

   --here i dont want to show anything 

WHEN 2 THEN 'CARD'
     --here i have to display cardno and bankname [store into @temptable]

ELSE 'UNKNOWN'

END

FROM PAYMENT_DETAILS 


SELECT * FROM  @TEMPTABLE
Posted
Updated 27-Nov-12 0:37am
v2

Try :

SELECT CUSNAME, CASE (PAYMENTMODE)
WHEN 1 THEN 'CASH'
WHEN 2 THEN 'CARD'+CARDNO+' '+BANKNAME
ELSE 'UNKNOWN'
END
FROM PAYMENT_DETAILS
 
Share this answer
 
Comments
Umapathi K 27-Nov-12 6:27am    
i am using in this report in report its giving big straight line., i want bankname in second line., any idea about this?
kashif Atiq 27-Nov-12 6:41am    
are you using crystal reports? for reporting
Umapathi K 27-Nov-12 6:47am    
yes
Here more optimized solution


SQL
INSERT INTO @TEMPTABLE
(
	CUSNAME,PAYMENT_MODE,CARDNO,BANKNAME
)
 
SELECT CUSNAME,

PAYMENTMODE,

CASE (PAYMENTMODE)
WHEN 1 THEN ''
WHEN 2 THEN PAYMENT_DETAILS.CARDNO
ELSE 'UNKNOWN'
END,

CASE (PAYMENTMODE)
WHEN 1 THEN ''
WHEN 2 THEN PAYMENT_DETAILS.BANKNAME
ELSE 'UNKNOWN'
END

FROM PAYMENT_DETAILS
 
Share this answer
 
v2
TRY THIS

SQL
DECLARE @TEMPTABLE TABLE
(
CUSNAME NVARCHAR(450),
PAYMENT_MODE nvarchar(250),
CARDNO nvarchar(450),
BANKNAME nvarchar(450)
)

INSERT INTO @TEMPTABLE
(
CUSNAME,PAYMENT_MODE,CARDNO,BANKNAME
)
SELECT 
PAYMENT_DETAILS.CUSNAME,
'CASH',
'',
''
FROM PAYMENT_DETAILS where PAYMENTMODE = 'CASH'


INSERT INTO @TEMPTABLE
(
	CUSNAME,PAYMENT_MODE,CARDNO,BANKNAME
)
SELECT 
PAYMENT_DETAILS.CUSNAME,
'CARD',
PAYMENT_DETAILS.CARDNO,
PAYMENT_DETAILS.BANKNAME
 
FROM PAYMENT_DETAILS where PAYMENTMODE = 'CARD'


INSERT INTO @TEMPTABLE
(
	CUSNAME,PAYMENT_MODE,CARDNO,BANKNAME
)
SELECT 
PAYMENT_DETAILS.CUSNAME,
'UNKNOWN',
'',
''
 
FROM PAYMENT_DETAILS where PAYMENTMODE != 'CARD' AND PAYMENTMODE != 'CASH'

SELECT * FROM @TEMPTABLE
 
Share this answer
 
v2
Comments
Umapathi K 27-Nov-12 6:29am    
FROM PAYMENT_DETAILS where PAYMENTMODE != 'CARD' AND PAYMENTMODE != 'CASH'
can u explain this please
kashif Atiq 27-Nov-12 6:40am    
its for your 'unknown' condition that you are using with ELSE in CASE satatement

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900