help with query

I have an application that throws a query to the srss report builder and then the report spits out.
im trying to bypass the application and test the query directly on the sql server using management studio.

I get the error  
must declare the scalar variable "@startdate".

I imagine the application is passing along these scalar values and I don't see them when I look at the query itself.
anway, how do I declare a scalar variable.  
here is part of the query

I think all the scalar values are preceded with the '@'

im unsure where to put these declarations in the query and how to
thanks a bunch

from
(SELECT DRAWERTRANSACTION.TENDER,
SUM(CASE WHEN DRAWERTRANSACTION.TRANTYPE='A' THEN DRAWERTRANSACTION.TRANAMT ELSE 0 END) AS ADJUSTEDTOTAL
FROM CASHIERING.DRAWERTRANSACTION DRAWERTRANSACTION INNER JOIN
CASHIERING.REGISTERTRANSACTION REGISTERTRANSACTION ON (DRAWERTRANSACTION.REGTRANNO=REGISTERTRANSACTION.REGTRANNO)
WHERE  (REGISTERTRANSACTION.STATUS<>'P' OR REGISTERTRANSACTION.REGTRANNO=1) AND DRAWERTRANSACTION.DRWRTRANNO>1
AND DRAWERTRANSACTION.TRANDTTM>= AND DRAWERTRANSACTION.TRANDTTM <=@StopDate AND (DRAWERTRANSACTION.DRWRKEY=@DrawerKey OR @DrawerKey=1)
GROUP BY DRAWERTRANSACTION.TENDER@StartDate) Summary
jamesmetcalf74Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael DyerSenior Systems Support AnalystCommented:
All of the names that start with "@" are variables.  You need to define them first like this:

DECLARE @start_date DATETIME
SET @start_date = '2/18/2015';
jamesmetcalf74Author Commented:
where should it fall in the query... at the very beginning?
Michael DyerSenior Systems Support AnalystCommented:
Looking at your query, you probably need to define @stopdate and @DrawerKey

Assuming DrawerKey is an interger, you would declare that variable this way:

DECLARE @DrawerKey int
SET @DrawerKey = 1;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michael DyerSenior Systems Support AnalystCommented:
Yes, these all should go at the very beginning, before you run the query
PortletPaulEE Topic AdvisorCommented:
something like this I suspect...
--declartions at the beginning
DECLARE @StartDate AS DATE, @StopDate AS DATE, @DrawerKey AS INT

-- give them values too
SET ...

SELECT
  *
FROM (
      SELECT
        DRAWERTRANSACTION.TENDER
      , SUM(CASE
          WHEN DRAWERTRANSACTION.TRANTYPE = 'A' THEN
            DRAWERTRANSACTION.TRANAMT
          ELSE
            0
        END) AS ADJUSTEDTOTAL
      FROM CASHIERING.DRAWERTRANSACTION DRAWERTRANSACTION
      INNER JOIN CASHIERING.REGISTERTRANSACTION REGISTERTRANSACTION
        ON (DRAWERTRANSACTION.REGTRANNO = REGISTERTRANSACTION.REGTRANNO)
      WHERE (REGISTERTRANSACTION.STATUS <> 'P' OR REGISTERTRANSACTION.REGTRANNO = 1)
      AND DRAWERTRANSACTION.DRWRTRANNO > 1
      AND DRAWERTRANSACTION.TRANDTTM >= @StartDate --<< something missing here
      AND DRAWERTRANSACTION.TRANDTTM <= @StopDate
      AND (DRAWERTRANSACTION.DRWRKEY = @DrawerKey OR @DrawerKey = 1)
      GROUP BY DRAWERTRANSACTION.TENDER
      --       , @StartDate --<< remove from the group by
      
      ) AS Summary

Open in new window


see lines 23 & 27 in particular, perhaps an error in the copy/paste of the query snippet in the question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.