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

  • You have some problems with your quotes. I'm not sure that I did the right corrections. Use the print to run the query that gets printed and debug from it.

    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)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2