If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > 'Execute immediate' context

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-11, 17:24
regtha regtha is offline
Registered User
 
Join Date: Jan 2010
Posts: 72
'Execute immediate' context

Hi,

When I run my script I am getting the below error msg. Please help me to fix this error. Thanks in advance.

Msg 11736, Level 15, State 0:
line 1: You cannot specify this command in an 'execute immediate' context.


Here is my script:

declare tbl_loop cursor for
select distinct name from sysobjects where type='U'
go

declare @sql varchar(250)
declare @tbl_name char(25)
open tbl_loop
fetch tbl_loop into @tbl_name
while (@@sqlstatus = 0 )
begin
select @sql = ' dbcc checktable('+@tbl_name+')'
print @sql
execute (@sql)
fetch tbl_loop into @tbl_name
end
close tbl_loop
deallocate cursor tbl_loop
go
END
Reply With Quote
  #2 (permalink)  
Old 01-18-11, 16:19
vineelaregonda vineelaregonda is offline
Registered User
 
Join Date: May 2009
Posts: 43
It's not possible to run the dbcc commands like
exec dbcc checktable(*****)
Reply With Quote
  #3 (permalink)  
Old 01-19-11, 02:26
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Code:
declare tbl_loop cursor for
select name from sysobjects where type='U'
go
declare @tbl_name char(25)
open tbl_loop
fetch tbl_loop into @tbl_name
while (@@sqlstatus = 0 )
begin
  dbcc checktable(@tbl_name)
  fetch tbl_loop into @tbl_name
end
close tbl_loop
deallocate cursor tbl_loop
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On