Harreni
asked on
Fixing Temp Table inside dynamic query
I had this question after viewing Create table dynamically while passing the table name.
Hi Experts,
How to fix this error in below query:
Invalid object name '#temp1'.
Thanks a lot in advance.
Harreni
Hi Experts,
How to fix this error in below query:
Invalid object name '#temp1'.
DECLARE @FindDuplicatedRowsInAsIsTableSQL varchar (MAX);
SET @FindDuplicatedRowsInAsIsTableSQL = N'SELECT
ID
,Name
,COUNT(*) MYCount
INTO #temp1
FROM MyTable
GROUP BY
ID
,Name
HAVING COUNT(*)>1'
EXECUTE(@FindDuplicatedRowsInAsIsTableSQL)
---Insert Duplicated Rows in AsIs_DupicatedRowsTable
DECLARE @InsertDuplicatedRowsIn_AsIsDupicatedRowsTableSQL varchar (MAX);
SET @InsertDuplicatedRowsIn_AsIsDupicatedRowsTableSQL = N'INSERT INTO Xtable
SELECT *
FROM #temp1';
EXECUTE(@InsertDuplicatedRowsIn_AsIsDupicatedRowsTableSQL)
Thanks a lot in advance.
Harreni
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER