I have created a stored procedure and want to use the following queries. It works but the scope of @ variable is lost when use in other query. Actually I want to use the value of @ variable in next INSERT Statement within the same stored procedure.
LIKE
DECLARE @TableName1 AS CHAR(25)
DECLARE @TableName2 AS CHAR(25)
SELECT @TableName1='TABLE1'
SELECT @TableName2='TABLE2'
EXEC ('DECLARE @ AS INTEGER SELECT @=MAX(Col1) FROM ' +@TableName1)
EXEC ('INSERT INTO ' +@TableName2+
'VALUES ('+@)
(Say TABLE2 has only one column)
Please comment it.
Akbar
(http://mondrian.sba.com/forums/Index.cfm