SQL QUERY: HOW TO IDENTIFY EXPIRED CREDIT CARDS BEFORE IT TRIES TO BILL TO THE CUSTOMERS.

Hello expert,
Wish collinsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
It's hard to guess without context.. something like

SELECT C.*
FROM CreditCards C
WHERE C.ExpiresDate <= GETDATE();

Open in new window


or a specific one


SELECT C.*
FROM CreditCards C
WHERE C.ExpiresDate <= GETDATE()
AND C.CreditCardNumber = '12312321312';

Open in new window

0
Wish collinsAuthor Commented:
Hello, I'm trying to write a stored procedure  to identify expired credit card before it tries to bill to the customers.
0
Justin EvansCommented:
Hi Wish,  

Can you paste what stored procedure you have so far?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Vitor MontalvãoMSSQL Senior EngineerCommented:
Where do you store the credit card information? It should also have the expiration date stored, right?
0
ste5anSenior DeveloperCommented:
Still only guessing:

CREATE PROCEDURE p_BillCreditCard
(
    @Amoung money,
    @CreditCardNumber nvarchar(255)
)
AS
    SET NOCOUNT ON;
    SET XACT_ABORT ON;

    -- Constants.
    DECLARE @CREDITCARD_EXPIRED int = 1;
    DECLARE @NO_ERROR int = 0;
    DECLARE @GENERIC_ERROR int = 55555;

    BEGIN TRY
        IF EXISTS(  SELECT C.*
                    FROM CreditCards C
                    WHERE C.ExpiresDate <= GETDATE()
                        AND C.CreditCardNumber = '12312321312')
        BEGIN
            RETURN @CREDITCARD_EXPIRED;
        END;

        -- Your billing code.
        RETURN @NO_ERROR;
    END TRY
    BEGIN CATCH
        IF @@trancount > 0
            ROLLBACK TRANSACTION;
        RETURN @GENERIC_ERROR;
    END CATCH;

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wish collinsAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.