Link to home
Start Free TrialLog in
Avatar of caglarkumanli
caglarkumanli

asked on

Exec

Hi all,

I want to run a select statement with EXEC keyword in my stored procedure.
For example EXEC ('SELECT * FROM USER WHERE USERID > 200').
And I want to store the result set in a temporary table in the stored procedure.
Is this possible?

Thanks...
Avatar of Ramesh Srinivas
Ramesh Srinivas
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes, it is.

EXEC('Create TABLE #Holding (id int, name varchar(50)) INSERT INTO #Holding Select ID, name From SomeTable where userid>200')

Broken down...

Create TABLE #Holding (id int, name varchar(50))
INSERT INTO #Holding
Select ID, name From SomeTable where userid>200


regards,

KS
ASKER CERTIFIED SOLUTION
Avatar of randeeps
randeeps

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial