0

I am writing a stored procedure by framing a dynamic string :

the following query is a string stored in a variable. How will I execute this string ?

 DELETE FROM PopularTrends          
 WHERE PopularID NOT IN           
 (          
 SELECT  PopularID          
 FROM   (SELECT *,          
           Row_number()          
             OVER(          
               PARTITION BY COUNTRY,HRefTopic          
               ORDER BY LastModifiedTime desc) AS RN          
    FROM   populartrends )A          
    WHERE  RN = 1          
 )  

1 Answer 1

2

Like this:

DECLARE @query NVARCHAR(1000)
SET @query=N'DELETE FROM PopularTrends          
 WHERE PopularID NOT IN           
 (          
 SELECT  PopularID          
 FROM   (SELECT *,          
           Row_number()          
             OVER(          
               PARTITION BY COUNTRY,HRefTopic          
               ORDER BY LastModifiedTime desc) AS RN          
    FROM   populartrends )A          
    WHERE  RN = 1          
 )'
EXEC sp_executesql @query

Reference:

Sign up to request clarification or add additional context in comments.

1 Comment

Would you know what that would be in BigQuery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.