Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SQL
CREATE PROCEDURE Procedure1
	@tableTypeItem MyTblType readonly
AS

	UPDATE v
		SET ONE=vi.ONE, TWO=vi.TWO
		FROM Table AS v JOIN @tableTypeItem AS vi ON v.ONE=vi.ONE
	WHERE
		v.ONE=vi.ONE

	exec Procedure2 ONE, THREE
GO


How can i access ONE and THREE (included in TableTYpe) from the exec line?

What I have tried:

I have tried to use a join, and also i tried out a declare on top of the exec. But it says me, that it is already declared.
Posted

1 solution

In SQL Server the table name cannot be variable. I believe it is to protect from SQL injection or other attacks.

The solution would be to parse your input argument yourself. Then construct the sql you want into a varchar variable. Once built you can run EXEC on that varchar variable.

Good Luck
Brent
 
Share this answer
 
Comments
Richard Deeming 22-Nov-23 3:57am    
The OP is using table-valued parameters[^].

Suggesting they switch to parsing a string and constructing dynamic SQL "for security reasons" must be a joke, right?!
Sascha Manns 22-Nov-23 4:14am    
Thats right. I spend time and googled further. Currently it looks like i have to change the Procedure2 to accept the table-Parameter and read it there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900