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

📱Build WhatsApp Bot using .NET + OpenAI

   In this article, you will learn how to build a real-world WhatsApp chatbot using ASP.NET Core and OpenAI. This bot can automatically repl...