General information
Forum:
Microsoft SQL Server
Hi!
I tried your code with the folowing changes, by eliminating the exec call:
declare @c1 varchar(500), @cnt int , @tbl varchar(300)
set @cnt = 1
set @tbl = !! did not see where you set this so I set it here
while @cnt <> 0 -- Reset to 0 when good!
begin
exec('Use '+ @db)
if exists (select * from syscolumns where name = @fld and id =
( select id from dbo.sysobjects where id = object_id(@tbl)
and OBJECTPROPERTY(id, 'IsUserTable') = 1 )
)
begin
set @cnt = @cnt+1
Set @fld = @fld+'_'+cast(@cnt as varchar)
print @fld
end
else
begin
set @cnt = 0
print 'Field Does Not Exist'
end
end
Hope it helps!
Ramona
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only