How can sole that

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AliHabib
    New Member
    • Dec 2008
    • 11

    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
    Code:
    set nocount on
    create table #DISTINCTC(
      [name] nvarchar(120)
    )
    insert into #DISTINCTC SELECT Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'AGEN'
    ------------------------
    select * from #DISTINCTC
    declare Dist cursor for
     select [name]from #DISTINCTC 
    open Dist
    DECLARE @z int
    declare @x nvarchar(120)
    declare @y nvarchar(120)
    fetch next from Dist into @x
     while @@fetch_status=0
     begin 
    set @y = @x;
     set @z=EXEC('select count(distinct '+@y+') from AGEN')
    if (@z <= 10)
     begin
      set nocount on
      create table #DISTINCTC1(
        DistinctVal nvarchar(4000)
      )
      insert into #DISTINCTC1 EXEC('select distinct '+@y+' from AGEN')
      ------------------------ 
      declare Insertion cursor for
      select * from #DISTINCTC1
      open #DISTINCTC1
      Declare @I nvarchar(4000)
      FETCH NEXT FROM Insertion INTO @I
      WHILE @@FETCH_STATUS = 0
       begin
       EXEC('insert into SATIS values("AGEN",'+@y+','+@I+')') 
       FETCH NEXT FROM Insertion INTO @I
       end
     
     end
    fetch next from Dist into @x 
     end
    close Insertion
    Deallocate Insertion
    close Dist 
    Deallocate Dist 
    drop table #DISTINCTC
    what shall I do
Working...