Is it possible to do something similar to the following in SQL Server 2012?
IF EXISTS (
WITH DATA AS (
SELECT *,
ROW_NUMBER() OVER(PARTITION BY column ORDER BY Column) AS rn
FROM table )
SELECT *
FROM DATA
WHERE rn = 2 )
BEGIN
...
END
I tried using this syntax and received an error. If this is not possible, would using a temp table be the best way to accomplish this?
IF EXISTS (SELECT * FROM table)
?WHERE rn = 2
IF EXISTS (SELECT column FROM dbo.table GROUP BY column HAVING COUNT(*)>1)