Home Forums SQL Server 7,2000 General Syntax error in Dynamic SQL - SQL Server 2000 RE: Syntax error in Dynamic SQL - SQL Server 2000

  • Hi Luis,

    Thank you very much for your suggesstion. With one change, your solution worked. I just had to make the following changes to the line containing the 'from' clause. Changed the triple ticks to single ticks. Here is the working script:

    use webproxy

    DECLARE @tempsql varchar(2000)

    select @tempsql =

    'declare @xmonth varchar(2)

    declare @xyear varchar(4)

    declare @xdate varchar(10)

    declare @rptmonth datetime

    select @xmonth = MONTH(dateadd(month,-1,getdate()))

    select @xyear = YEAR(dateadd(month,-1,getdate()))

    select @xdate = @xmonth + ''/01/'' + @xyear

    select @rptmonth = cast(@xdate as datetime)

    set rowcount 0

    select dbo.user_parser(clientusername) as "_user",

    count(*) as "objects",

    sum(cast(bytessent as float))as "bytes_sent",

    sum(cast(bytesrecvd as float))as "bytes_received",

    (sum(cast(bytessent as float)) + sum(cast(bytesrecvd as float)))as "total_bytes",

    @rptmonth as "rpt_month"

    ----into ##top100temp

    from webproxylog' + cast(month(dateadd(m,-2,getdate())) as varchar(2)) + '

    --from webproxylog5

    where dbo.user_parser(clientusername) <> '' ''

    group by dbo.user_parser(clientusername)

    order by total_bytes desc'

    --print @tempsql

    execute (@tempsql)

    By the way, how would I mark this post as 'RESOLVED', or 'CLOSED' or something like that?

    Thank you so much and continued success,

    Seyed