Monday, 24 June 2013

Validating Credit or Debit Card Using Small SQL Query



Hi All

Validating Credit or Debit Card using SQL


I have only the Expiry Date Of Credit/Debit Card in String formate like '2012-09' .

If i pass this as input and i need to get only the valid cards data.

declare @exptbl table(id int,expdate varchar(50))
insert into @exptbl values(1,'2012-09')
insert into @exptbl values(2,'2012-02')
insert into @exptbl values(3,'2012-05')
insert into @exptbl values(4,'2013-06')
insert into @exptbl values(5,'2013-07')

If u query the table variable you will get below out put ,according to our requirement  i  need to get only Marked Records.

I want Below output :


For Getting above output please use below query:

SELECT * FROM @EXPTBL
WHERE CONVERT(DATETIME,EXPDATE+'-01')>=CONVERT(DATETIME,CONVERT(VARCHAR(50),DATEPART(YYYY,GETDATE()))+'-'+CONVERT(VARCHAR(50),DATEPART(MM,GETDATE()))+'-01')

Thanks for Visiting the Blog
Santosh 
  

No comments:

Post a Comment