I am trying to run the following dynamic SQL:
declare @ebodbname varchar(255), @SQL varchar(1000)
Select @ebodbname = host_db_name from host_db_name
set @SQL = "declare @EBOID integer" + CHAR(13)
set @SQL = @SQL + "select @EBOID = EBOID from " + @ebodbname + "..EBO where ebodatabase = db_name()" + CHAR(13)
set @SQL = @SQL + "select @EBOID"
execute(@SQL)
I have two databases. The name of the 2nd database is stored in a table in the first database.
What the SQL does is retrieve the name of a database from the table and then query a table that exists in that database using the variable retrieved.
My problem is I cannot read the variable outside of the dynamic SQL. I need to be able to access the variable @EBOID OUTSIDE of the DSQL. So that I can use it in a normal query outside.
For e.g:
insert into table values(@EBOID, ....etc.
Thanks in advance
declare @ebodbname varchar(255), @SQL varchar(1000)
Select @ebodbname = host_db_name from host_db_name
set @SQL = "declare @EBOID integer" + CHAR(13)
set @SQL = @SQL + "select @EBOID = EBOID from " + @ebodbname + "..EBO where ebodatabase = db_name()" + CHAR(13)
set @SQL = @SQL + "select @EBOID"
execute(@SQL)
I have two databases. The name of the 2nd database is stored in a table in the first database.
What the SQL does is retrieve the name of a database from the table and then query a table that exists in that database using the variable retrieved.
My problem is I cannot read the variable outside of the dynamic SQL. I need to be able to access the variable @EBOID OUTSIDE of the DSQL. So that I can use it in a normal query outside.
For e.g:
insert into table values(@EBOID, ....etc.
Thanks in advance