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 

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2008-02-15 : 07:53:06

Hi guys

I have temp table (#abc) which holds the data i am opening a cursor and based on the value in temp table i get 2 columns from other table which will be field name and table name. based on these 2 i need to get the value and update the temp table.

Problem i have, is when i build a qry the out put of it shd be updated back to temp table which is not avaiable in exec


declare @sql varchar(8000)
declare @tbl varchar(200)
declare @fld varchar(200)
declare @val varchar(200)

select @tbl=AMS_MEASURE_TABLE_NAME, @fld=AMS_MEASURE_TABLE_FIELD from
ATTRIBUTE where ATTR_ID=6 and AMS_ID=1
set @sql='select ' + @fld + ' from '+ @tbl + ' where prj_id=1'
exec (@sql)


ideas, tips welcome

======================================
Ask to your self before u ask someone

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-15 : 08:00:04
quote:
Originally posted by khalik


Hi guys

I have temp table (#abc) which holds the data i am opening a cursor and based on the value in temp table i get 2 columns from other table which will be field name and table name. based on these 2 i need to get the value and update the temp table.

Problem i have, is when i build a qry the out put of it shd be updated back to temp table which is not avaiable in exec


declare @sql varchar(8000)
declare @tbl varchar(200)
declare @fld varchar(200)
declare @val varchar(200)

select @tbl=AMS_MEASURE_TABLE_NAME, @fld=AMS_MEASURE_TABLE_FIELD from
ATTRIBUTE where ATTR_ID=6 and AMS_ID=1
set @sql='insert into #abc (fields...)
select ' + @fld + ' from '+ @tbl + ' where prj_id=1'
exec (@sql)


ideas, tips welcome

======================================
Ask to your self before u ask someone



cant you add the insert bit too inside the qry string?
Go to Top of Page
   

- Advertisement -