Suppose I have a table like :
(0 means in cash and any other value indicates check serial number
)
ID NAME PaymentMethod Amount Bank
------------------------------------------------------------
1 Alex 0 20 ''
2 Sara 123456789 5000 Bank of America
3 Mina 0 15 ''
4 Scott 987456321 10000 Citibank
How can I use an IF
statement so that if the PaymentMethod
column contains 0
I hide this column and instead show a column with value of Incash
and hide the bank column as well.
And when the PaymentMethod
is anything else I just rename the column header to CheckSerial
.
To make it more clear I want the table to look like this; for those who have paid InCash
, it shows up as:
ID NAME PaymentMethod Amount
-------------------------------------------
1 Alex InCash 20
3 Mina InCash 15
for those how have paid by checks, it shows up as :
ID NAME PaymentMethod Serial Number Amount Bank
-------------------------------------------------------------------
2 Sara Check 123456789 5000 Bank of America
4 Scott Check 987456321 10000 Citibank
I tried something like this , based on the given IDs,only one select statement executes:
ALTER FUNCTION dbo.Function1(@IDTag bigint)
RETURNS TABLE
AS
if PaymentMethod = 0
BEGIN
RETURN SELECT ID, Name , PaymentMethod = InCash , Amount
FROM tblTest
WHERE (ID = @IDTag)
END
ELSE
BEGIN
RETURN SELECT ID, Name , PaymentMethod ='By Check', PaymentMethod As [Serial number], Amount, Bank
FROM tblTest
WHERE (ID = @IDTag)
END
Is this even correct? If this is not feasible or logical what better way can you suggest on this?