Saturday, April 13, 2013

Get Select Statement in a Variable SQL Server

DECLARE @remain VARCHAR(max)
DECLARE @MID VARCHAR(255) SET @MID=5
SET @remain='SELECT DATEDIFF(dd,GETDATE(),DateAdd(mm, mt.ValidMonth, py.UpdatedDate-1))
        FROM Payment.PaymentTransaction py
        INNER JOIN Member.BasicInfo B3 ON b3.MemberID=py.MemberID
        INNER JOIN Master.MemberType mt ON mt.MemberTypeID=b3.MemberTypeID
WHERE '
SET @remain=@remain +'b3.MemberID='+@MID
PRINT @remain
EXEC(@remain)

Note:(make sure your all declare variable must be same data type)

No comments:

Post a Comment

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...