By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

How can sole that

P: 11
I have a code when running it give this error messege (in sql server 2000)
Server: Msg 156, Level 15, State 1, Line 20
Incorrect syntax near the keyword 'EXEC'.

this is a part of the code
Expand|Select|Wrap|Line Numbers
  1. set nocount on
  2. create table #DISTINCTC(
  3.   [name] nvarchar(120)
  4. )
  5. insert into #DISTINCTC SELECT Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'AGEN'
  6. ------------------------
  7. select * from #DISTINCTC
  8. declare Dist cursor for
  9.  select [name]from #DISTINCTC 
  10. open Dist
  11. DECLARE @z int
  12. declare @x nvarchar(120)
  13. declare @y nvarchar(120)
  14. fetch next from Dist into @x
  15.  while @@fetch_status=0
  16.  begin 
  17. set @y = @x;
  18.  set @z=EXEC('select count(distinct '+@y+') from AGEN')
  19. if (@z <= 10)
  20.  begin
  21.   set nocount on
  22.   create table #DISTINCTC1(
  23.     DistinctVal nvarchar(4000)
  24.   )
  25.   insert into #DISTINCTC1 EXEC('select distinct '+@y+' from AGEN')
  26.   ------------------------ 
  27.   declare Insertion cursor for
  28.   select * from #DISTINCTC1
  29.   open #DISTINCTC1
  30.   Declare @I nvarchar(4000)
  31.   FETCH NEXT FROM Insertion INTO @I
  32.   WHILE @@FETCH_STATUS = 0
  33.    begin
  34.    EXEC('insert into SATIS values("AGEN",'+@y+','+@I+')') 
  35.    FETCH NEXT FROM Insertion INTO @I
  36.    end
  37.  
  38.  end
  39. fetch next from Dist into @x 
  40.  end
  41. close Insertion
  42. Deallocate Insertion
  43. close Dist 
  44. Deallocate Dist 
  45. drop table #DISTINCTC
what shall I do
Jan 27 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.