?
Solved

what causes errror Must declare the scalar variable "@Subsidiary".

Posted on 2010-01-08
3
Medium Priority
?
996 Views
Last Modified: 2013-11-16
DECLARE            @BeginDate            DATETIME      = '07/01/2009';
                  @EndDate            DATETIME      = '01/05/2010';
                  @Subsidiary     INT                  = 2;
                  @Contract            VARCHAR(20)      = 'KD228';

SET @BeginDate = '07/01/2009';
      @EndDate = '01/05/2010';
      @Subsidiary = 2;
      @Contract= 'KD228';
--AS

--SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED


SELECT  CASE
                  WHEN @Subsidiary = 1
                  AND (RIGHT (RTRIM(R.CSTBTablCode),3)= 'DCF' AND TN.CSTBTablCode != '3')
                  THEN 'Error'
                  WHEN @Subsidiary = 1
                  AND (RIGHT (RTRIM(R.CSTBTablCode),3)= 'TNF' AND TN.CSTBTablCode = '3')
                  THEN 'Error'
                  WHEN @Subsidiary = 2
                  AND (SUBSTRING(R.CSTBTablCode,4,1)!= 'T' AND TN.CSTBTablCode != '3')
                  THEN 'Error'
                  WHEN @Subsidiary = 2
                  AND (SUBSTRING(R.CSTBTablCode,4,1) = 'T' AND TN.CSTBTablCode = '3')
                  THEN 'Error'
                  WHEN @Subsidiary = 2
                  AND (C.CSTBTablCode = '01' OR C.CSTBTablCode = '1')
                  THEN 'Error'
                  ELSE ''
            END                                                            AS ErrorFlag,
            TN.CSTBTablCode+'-'+TN.CSTBTablDesc            AS TANFType,
            R.CSTBTablCode                                          AS RU,
            C.CSTBTablCode                                          AS CostCenter,
            CASE
                  WHEN ((@Subsidiary = 2 AND LEFT (RIGHT (R.CSTBTablCode,6),1) = '1')
                         OR (@Subsidiary = 1 AND RIGHT (LEFT (R.CSTBTablCode,3),1) = '1')) THEN 'AMH'
                  WHEN ((@Subsidiary = 2 AND LEFT (RIGHT (R.CSTBTablCode,6),1) = '2')
                         OR (@Subsidiary = 1 AND RIGHT (LEFT  (R.CSTBTablCode,3),1) = '2')) THEN 'ASA'
                  WHEN ((@Subsidiary = 2 AND LEFT (RIGHT (R.CSTBTablCode,6),1) = '3')
                         OR (@Subsidiary = 1 AND RIGHT (LEFT  (R.CSTBTablCode,3),1) = '3')) THEN 'CMH'
                  WHEN ((@Subsidiary = 2 AND LEFT (RIGHT (R.CSTBTablCode,6),1) = '4')
                         OR (@Subsidiary = 1 AND RIGHT (LEFT  (R.CSTBTablCode,3),1) = '4')) THEN 'CSA'
            END                                                      AS Prog,
            P.CSTBTablCode                                    AS ProcCode,
            P.CSTBStatOvcd                                    AS StatCode,
            F.CSTBTablDesc                                    AS Funding,
            CONVERT (varchar,T.ARTRTranDate,101)      AS BatchDate,
            CASE
                  WHEN (T.ARTRDaodFlag = 1 AND T.ARTREditEror = 2) THEN 'Yes'
                  ELSE 'Error'
            END                                                      AS Transmit,
            --ARTRClntTime,
            X.ARCSCustCode,
            T.ARTRTranCtrl                                    AS Control,
            S.ARSLOldcNumb                                    AS StaffID,
            S.ARSLSlmnDesc                                    AS Staff,
            
            R.CSTBStatCntr                                    AS RUContract,
            T.ARTRStatCntr                                    AS TransContract

FROM      KIS1.dbo.ARTran AS T

INNER       Join KIS1.dbo.CSTabl AS R ON R.CSTBRecdCtrl = T.ARTRReptUnit

INNER      JOIN KIS1.dbo.CSTabl AS F ON F.CSTBRecdCtrl =  R.CSTBSrvcFnd1

INNER       Join KIS1.dbo.CSTabl AS P ON P.CSTBRecdCtrl = T.ARTRSrvcCode

INNER      JOIN KIS1.dbo.CSTabl AS C ON C.CSTBRecdCtrl = T.ARTRStffCscn

INNER       JOIN KIS1.dbo.ARCust AS X ON X.ARCSCustCtrl = T.ARTRCustCtrl

INNER       JOIN KIS1.dbo.ARSale AS S ON S.ARSLSlmnCtrl = T.ARTRSaleCtrl

INNER      JOIN KIS1.dbo.CSAdmn AS A ON T.ARTRAdmsCtrl = A.CSADRecdCtrl

LEFT      JOIN KIS1.dbo.CSTabl AS TN ON TN.CSTBRecdCtrl = A.CSADTanfFlag
                                                
            

WHERE      T.ARTRSbsdCtrl = @Subsidiary AND
            T.ARTRPendFlag = 2 AND
            T.ARTRRecdType = 0 AND
            T.ARTREntyType = 191 AND
            --T.ARTRSendStat = 1 AND
            T.ARTRDaodFlag = 1 AND
            ((T.ARTRStatCntr = 'KD228') OR (R.CSTBStatCntr  LIKE '%KD228%'  AND T.ARTRStatCntr Is Null )) AND
            T.ARTRTranDate BETWEEN @BeginDate AND @EndDate
            


ORDER BY 1,4,3,T.ARTRTranCtrl
0
Comment
Question by:aircon
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 26210588
a typo?
0
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 total points
ID: 26210868
The problem is somewhere else:

Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.

and some more problems...

So, fix your declarations:

DECLARE @BeginDate DATETIME,
               @EndDate DATETIME,
               @Subsidiary INT,
               @Contract VARCHAR(20);

SET      @BeginDate = '07/01/2009'
SET      @EndDate = '01/05/2010'
SET      @Subsidiary = 2
SET      @Contract= 'KD228'
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What we learned in Webroot's webinar on multi-vector protection.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question