Home Forums SQL Server 2008 SQL Server 2008 - General how to write a stored procedure to check if the members membership has expired RE: how to write a stored procedure to check if the members membership has expired

  • jameslester78 (11/24/2012)


    create database example

    GO

    USE example

    GO

    Create table tbl_a (email varchar (20),membershipexpiry date)

    insert into tbl_a VALUES

    ('a@a.com','01-Jan-2012'),('b@a.com','01-Jan-2013')

    GO

    Create proc proc_a

    @email varchar(20)

    as

    declare @v-2 date =

    (select membershipexpiry from tbl_a where email = @email)

    if @v-2<GETDATE() select 1 as expired

    if @v-2>GETDATE() select 0 as expired

    Go

    exec proc_a @email = 'a@a.com'

    exec proc_a @email = 'b@a.com'

    GO

    use master

    drop database example

    Normally, a "1" as a return is considered to be a "Yes" or "True" answer. My recommendation would be to change the name of the returned column from "expired" to "IsActive" just to avoid any confusion down the road.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)