Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic Sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-11-30 : 09:28:25
Pavan writes "Hi! All

I want to execute a dynamic sql in which i am inserting a records from a select statment to a temporary
table.
My select statment will select a records from a link server database. Here the Links server database
name is store in a table. So i will be getting it from the table and depending upon the value i want
to execute the sql statment to that server.


here is my code



alter procedure p_temp
as
BEGIN
set nocount on
declare @st1 varchar(50)
declare @st2 varchar(1000)
declare @st3 varchar(1000)

declare @t_t (c0 varchar(100),c1 int ,c2 varchar(100),c3 varchar(100))

select @st3= "Insert @t_t
select 'Fixed value', c2,c3,c3
from Linked_server..user.tablename "
/* Here i want tthe Linked server should be varying from time to time.

e.g
select @t=linkservername from table1 where c1='34'

select @st3= "Insert @t_t
select 'Fixed value', c2,c3,c3
from @t..user.tablename "





*/
print @st3
print 'go'
select * from @t_t

END"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-11-30 : 09:51:37
These should help:

http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619

Go to Top of Page
   

- Advertisement -