Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7733625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:02:38+00:00 2026-06-01T07:02:38+00:00

I am creating a tickets opened vs resolved per week gadget that reports back

  • 0

I am creating a tickets opened vs resolved per week gadget that reports back as far as the number of days that the user supplies.

My problem is that powergadgets (the gadget make I am using) throws an error when I try to run the below code:

The variable name ‘@NoOfDays’ has already been declared. Variable names must be unique within a query batch or stored procedure.

As you can see, I need to use this variable twice. If I add Declare @NoOfDays int at the beginning, powergadgets just crashes. I am pretty new to SQL, but in the past using a user-passed variable twice has never caused problems. What can I do to resolve the issue?

SELECT        
    a.resolved, b.opened, 
    a.weekClosed AS week, 
    a.yearClosed AS year, 
    CAST(a.yearClosed as varchar(5)) + ', ' + CAST(a.weekClosed as varchar(5)) AS period
FROM            
    (SELECT        
         TOP (100) PERCENT COUNT(DISTINCT TicketNbr) AS resolved,
         { fn WEEK(date_closed) } AS weekClosed,
         { fn YEAR(date_closed) } AS yearClosed
     FROM v_rpt_Service
     WHERE        
         (date_closed >= DateAdd(Day, DateDiff(Day, 0, GetDate()) - @NoOfDays, 0))
     GROUP BY 
         { fn WEEK(date_closed) }, { fn YEAR(date_closed) }
    ) AS  a 
LEFT OUTER JOIN
    (SELECT TOP (100) PERCENT 
         COUNT(DISTINCT TicketNbr) AS opened, 
         { fn WEEK(date_entered) } AS weekEntered,
         { fn YEAR(date_entered) } AS yearEntered
     FROM 
         v_rpt_Service AS v_rpt_Service_1
     WHERE        
         (date_entered > = DateAdd(Day, DateDiff(Day, 0, GetDate()) - @NoOfDays, 0))
     GROUP BY 
         { fn WEEK(date_entered) }, { fn YEAR(date_entered) }
    ) AS b ON a.weekClosed = b.weekEntered AND a.yearClosed = b.yearEntered
ORDER BY 
    year, week
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:02:40+00:00Added an answer on June 1, 2026 at 7:02 am

    This looks like a bug within Powergadgets, and the way it wraps queries. to me. It is examining the query, seeing two searches, each with a required variable, and then tries creating them as parameters. Hence you get the duplicate declaration error.

    Suggestion – change the variable name in the second query, and then pass the value in twice (essentially creating two parameters). If it works, then we know that Powergadgets has a problem with variables being used twice in slightly different scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that a user would fill out while creating a ticket
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
I have thought some time about creating a PHP-based customer-service thingy that assigns different
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Creating an installer for possible remote systems so that if they do not have
I know that current Git submodules are not supported by AppHarbor (as per this
I am creating a web service that queries my database and returns a list
I'm creating an application that will get the contents of a cookie storing a
I've been tasked with creating some sort of service that will take any e-mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.