468,316 Members | 1,992 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

How can sole that

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
0 898

Post your reply

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

Similar topics

1 post views Thread by sentinel | last post: by
1 post views Thread by fartsniff | last post: by
2 posts views Thread by ChronicFatigue | last post: by
1 post views Thread by Timothy Rue | last post: by
reply views Thread by O=O=O AriZOnA O=O=O | last post: by
3 posts views Thread by KavvY | last post: by
3 posts views Thread by Chris Forone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.