Must declare the scalar variable

I Am getting error as Must declare the scalar variable "@Imageid" for the following code,while executing,
exec spGetPager  ' ' , ' ', ' 3 ', ' '
In my coding I pass querystring value like 1,2,3 etc
CREATE PROCEDURE spGetPager
      @PageNo int = 1,  
      @ItemsPerPage int = 1,  
 @Imageid int,
      @TotalRows int out  
AS  
BEGIN  
  SET NOCOUNT ON  
  DECLARE  
    @StartIdx int,  
    @SQL nvarchar(max),   
    @SQL_Conditions nvarchar(max),   
    @EndIdx int
      IF @PageNo < 1 SET @PageNo = 1  
      IF @ItemsPerPage < 1 SET @ItemsPerPage = 10  
      SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1  
      SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1  
      SET @SQL = 'SELECT Imageid,Imagepath,imagename,username  
                FROM (  
                SELECT  ROW_NUMBER() OVER(ORDER BY Imageid) AS Row, *  
                      FROM  Imageupload ) AS tbl WHERE Imageid=@Imageid AND Row >= '  
                                    + CONVERT(varchar(9), @StartIdx) + ' AND  
                       Row <=  ' + CONVERT(varchar(9), @EndIdx)  
      EXEC sp_executesql @SQL  
      SET @SQL = 'SELECT @TotalRows=COUNT(*) FROM Imageupload'  
      EXEC sp_executesql  
        @query = @SQL,  
        @params = N'@TotalRows INT OUTPUT',  
        @TotalRows = @TotalRows OUTPUT  
END
Thanks in Advance

you cant use variable directly in concatenation operator as its of type int. you need to cast it first as below
CREATE PROCEDURE spGetPager
@PageNo int = 1,
@ItemsPerPage int = 1,
@Imageid int,
@TotalRows int out
AS
BEGIN
SET NOCOUNT ON
DECLARE
@StartIdx int,
@SQL nvarchar(max),
@SQL_Conditions nvarchar(max),
@EndIdx int
IF @PageNo < 1 SET @PageNo = 1
IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
SET @SQL = 'SELECT Imageid,Imagepath,imagename,username
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY Imageid) AS Row, *
FROM Imageupload ) AS tbl WHERE Imageid=' + CAST(@Imageid AS varchar(50)) + ' AND Row >= '
+ CONVERT(varchar(9), @StartIdx) + ' AND
Row <= ' + CONVERT(varchar(9), @EndIdx)
EXEC sp_executesql @SQL
SET @SQL = 'SELECT @TotalRows=COUNT(*) FROM Imageupload'
EXEC sp_executesql
@query = @SQL,
@params = N'@TotalRows INT OUTPUT',
@TotalRows = @TotalRows OUTPUT
END
That being I didnt understand why you need dynamic sql here. There's no dynamicity involved as i see
 you could simply use a sql like below
CREATE PROCEDURE spGetPager
@PageNo int = 1,
@ItemsPerPage int = 1,
@Imageid int,
@TotalRows int out
AS
BEGIN
SET NOCOUNT ON
DECLARE
@StartIdx int,
@EndIdx int
IF @PageNo < 1 SET @PageNo = 1
IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
SELECT Imageid,Imagepath,imagename,username
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY Imageid) AS Row, *
FROM Imageupload ) AS tbl WHERE Imageid=@Imageid
AND Row >= @StartIdx
AND Row <= @EndIdx
SELECT @TotalRows=COUNT(*) FROM Imageupload
END
to achieve same requirement.
Make sure you read
http://www.sommarskog.se/dynamic_sql.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Getting "Must declare the scalar variable" Error

    Hello All,
    I have write following query to block invoice which has Prices not equal to PriceList as below.
    -- To Block Invoices which has Prices not equal to PriceList
    IF (@transaction_type='A' OR @transaction_type = 'U') AND CAST(@OBJECT_TYPE = '18')
    BEGIN
        SELECT T1.ItemCode,
                T1.Price AS PO_Price,
                T2.U_ListPrice AS Listed_Price
            FROM OPCH AS T0 
            INNER JOIN
            PCH1 AS T1 ON
            T0.DocEntry = T1.DocEntry
            LEFT OUTER JOIN    
            [dbo].[@PRICELISTS] AS T2 ON
            T1.ItemCode = T2.U_ItemNo
        WHERE
                    T1.DocEntry = @list_of_cols_val_tab_del) AND
            (T1.Price <> T2.U_ListPrice)   
    BEGIN
    SET @error = 123
    SET @error_message = 'Deviation in price'
    END
    END
    But after Execution got following Errors
    Msg 137, Level 15, State 2, Line 2
    Must declare the scalar variable "@transaction_type".
    Msg 137, Level 15, State 2, Line 19
    Must declare the scalar variable "@list_of_cols_val_tab_del".
    Msg 137, Level 15, State 1, Line 22
    Must declare the scalar variable "@error".
    Msg 137, Level 15, State 1, Line 23
    Must declare the scalar variable "@error_message".
    Please Help
    Regards
    Hitul

    Hi Hitul,
    Please check Snapshot.
    Please see Red Lines for SBO_SP_TransactionNotification Procedure.
    Paste your code below ADD YOUR CODE HERE.
    Hope this help
    Regards::::
    Atul Chakraborty

  • Must declare the Scalar variable *@prompt*.. (IES 10901)".

    Hi,
    I am getting an error: "Database error Must declare the Scalar variable *@prompt*.. (IES 10901)".
    backend: SQLServer
    The dim, Lovs are valid in IDT universe.
    There is a Fiscal Year Month Dim in Universe=SELECT
      cast(convert(varchar(6),DATEADD (YEAR,"COST_SUMMARY_FACT_VR"."FISC_YEAR"-1900,DATEADD(MONTH,"COST_SUMMARY_FACT_VR"."FISC_PERIOD"-1,DATEADD(DAY,0,0 ))),112) as int)
    FROM "COST_SUMMARY_FACT_VR"
    Lov
    There are two LOVs FP_From, FP_To
    1) FP_From= select distinct cast(convert(varchar(6),DATEADD (YEAR,"COST_SUMMARY_FACT_VR"."FISC_YEAR"-1900,DATEADD(MONTH,"COST_SUMMARY_FACT_VR"."FISC_PERIOD"-1,DATEADD(DAY,0,0 ))),112) as int) from COST_SUMMARY_FACT_VR order by 1
    2) FP_To=select distinct cast(convert(varchar(6),DATEADD (YEAR,"COST_SUMMARY_FACT_VR"."FISC_YEAR"-1900,DATEADD(MONTH,"COST_SUMMARY_FACT_VR"."FISC_PERIOD"-1,DATEADD(DAY,0,0 ))),112) as int) from COST_SUMMARY_FACT_VR order by 1
    Prompts
    There are two universe prompts
    1) FP_From is Numeric and LOV FP_From is attached
    2) FP_To is Numeric and LOV FP_To is attached
    Using the universe prompts in webi as
    Fiscal Year Month between FP_From and FP_To
    Qry is executing perfectly in backend.

    In addition to Visakh's solution: the reason you got the error message is because the piece of dynamic SQL is not part of the stored procedure, but constiutes a scope of its own. Thus variables declared in the surrounding procedure are not visible.
    Also, you should the dynamic SQL this way:
    SET @sql = N'
    SELECT @Result=COUNT( Id ) FROM  ' + quotename(@TableName) +
    ' WHERE RunRegisterKey=@ID'
    SET @Params = N'@Result int OUTPUT, @ID int'
    EXEC sys.sp_executesql @sql,@Params,@Result = @Result OUT, @ID = @ID
    That is, use quotename for the table name, in case you have a table named
    sys.objects; SHUTDOWN WITH NOWAIT; --
    Furthermore, pass @ID as a parameter rather than concatenating it to the string. It is both easier and safer.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Must declare the scalar variable error

    I am getting the error "Must declare the scalar variable "@Result""  when i execute the below query
    declare @sql nvarchar(max),
    @tablename varchar(200),
    @Id int,
    @Result int
    set @tablename='xyz'
    set @id=1
    SET @sql = '
    SELECT @Result=COUNT( Id ) FROM  ' + @TableName+ ' WHERE RunRegisterKey=' +convert(nvarchar(100),@ID)  
    EXEC sys.sp_executesql @sql

    In addition to Visakh's solution: the reason you got the error message is because the piece of dynamic SQL is not part of the stored procedure, but constiutes a scope of its own. Thus variables declared in the surrounding procedure are not visible.
    Also, you should the dynamic SQL this way:
    SET @sql = N'
    SELECT @Result=COUNT( Id ) FROM  ' + quotename(@TableName) +
    ' WHERE RunRegisterKey=@ID'
    SET @Params = N'@Result int OUTPUT, @ID int'
    EXEC sys.sp_executesql @sql,@Params,@Result = @Result OUT, @ID = @ID
    That is, use quotename for the table name, in case you have a table named
    sys.objects; SHUTDOWN WITH NOWAIT; --
    Furthermore, pass @ID as a parameter rather than concatenating it to the string. It is both easier and safer.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Error must declare the scalar variable

    por que me marca ese error una consulta?
    DECLARE  @feci AS datetime
    DECLARE @fecf AS datetime
    SET @FECI=(SELECT DISTINCT(T0.DOCDATE) FROM ORTT T0 WHERE T0.DOCDATE='[%0]')
    SET @FECF=(SELECT DISTINCT(T0.DOCDATE) FROM ORTT T0 WHERE T0.DOCDATE='[%1]')
    EXEC DBO.COMPARATIVO @FECI,@FECF
    Edited by: mary merecias on Nov 17, 2011 3:15 PM

    el codigo no, son las variables. si pongo este código me marca que no tiene un select MUST SPECIFY TABLE TO SELECT FROM
    Declare @fec1 as datetime
    Declare @fec2 as datetime
    SET @fec1=[%0]
    SET @fec2=[%1]
    SELECT DISTINCT(T0.itemcode),T0.itemname,T0.onhand,     
          (SELECT SUM(PCH1.linetotal) AS TOTAL
               FROM OPCH
                  INNER JOIN pch1 on OPCH.docentry=PCH1.docentry
                INNER JOIN OITM ON OITM.ITEMCODE=PCH1.ITEMCODE
               WHERE pch1.targettype<>'19' and OITM.itemcode=T0.ITEMCODE AND OPCH.DOCDATE>=@FEC1 AND OPCH.DOCDATE<=@fec2)AS 'TOTAL COMPRAS',
         (SELECT SUM(PCH1.QUANTITY) AS TOTAL
               FROM OPCH
                  INNER JOIN pch1 on OPCH.docentry=PCH1.docentry
                INNER JOIN OITM ON OITM.ITEMCODE=PCH1.ITEMCODE
               WHERE pch1.targettype<>'19' and OITM.itemcode=T0.ITEMCODE AND OPCH.DOCDATE>=@fec1 AND OPCH.DOCDATE<=@fec2 ) AS 'PIEZAS COMPRADAS',
          (SELECT SUM(INV1.linetotal) AS TOTAL
               FROM OINV
                  INNER JOIN INV1 on OINV.docentry=INV1.docentry
                INNER JOIN OITM ON OITM.ITEMCODE=INV1.ITEMCODE
               WHERE INV1.targettype<>'14' and OITM.itemcode=T0.ITEMCODE AND OINV.DOCDATE>=@fec1 AND OINV.DOCDATE<=@fec2)AS 'TOTAL VENTAS',
         (SELECT SUM(INV1.QUANTITY) AS TOTAL
               FROM OINV
                  INNER JOIN INV1 on OINV.docentry=INV1.docentry
                INNER JOIN OITM ON OITM.ITEMCODE=INV1.ITEMCODE
               WHERE INV1.targettype<>'14' and OITM.itemcode=T0.ITEMCODE AND OINV.DOCDATE>=@fec1 AND OINV.DOCDATE<=@fec2 ) AS 'PIEZAS VENDIDAS'
         FROM OITM T0
    GROUP BY T0.itemcode,T0.itemname,T0.onhand
    en SQL SERVER si funciona bien
    Edited by: mary merecias on Nov 17, 2011 4:50 PM
    Edited by: mary merecias on Nov 17, 2011 4:51 PM
    Edited by: mary merecias on Nov 17, 2011 4:53 PM

  • Msg 137, Level 15, State 2, Line 29 Must declare the scalar variable "@ACTIVE_STATUS".

    USE [NC_DB]
    GO
    /****** Object:  StoredProcedure [dbo].[S_EDIT_USER]    Script Date: 12/23/2013 12:32:44 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[S_EDIT_USER]  
    (  @DSA_CODE VARCHAR(10)  
        ,@REQUESTOR_DEPT VARCHAR(40) 
        ,@ACTIVE_STATUS INT  
        ,@MAKER_ID VARCHAR(10)  
        ,@MAKER_IP VARCHAR(20)  
        ,@ERROR_CODE INT OUTPUT  
    AS  
    BEGIN  
    DECLARE @CNT INT;   
    DECLARE @SQL NVARCHAR(MAX);
    --DECLARE @REQUESTOR_DEPT VARCHAR(40);
    --print(@REQUESTOR_DEPT);
    SELECT @CNT = COUNT(*) FROM TMAS_UAM_USER_TMP WHERE DSA_CODE = @DSA_CODE;  
    IF @CNT > 0  
     SET @ERROR_CODE = 1;  
    ELSE  
     SET @ERROR_CODE = 0; 
    if @REQUESTOR_DEPT = 'N'
     SET @REQUESTOR_DEPT = ''; 
    ELSE  
     SET @REQUESTOR_DEPT = @REQUESTOR_DEPT ; 
     print @REQUESTOR_DEPT;
    IF @ERROR_CODE = 0
    set @SQL = 'INSERT INTO TMAS_UAM_USER_TMP (  
       DSA_CODE  
               ,DSA_NAME  
               ,DSA_CITY  
               ,DSA_PRODUCT  
               ,DSA_PHNO  
               ,DSA_MOBNO  
               ,DSA_RQSTR  
               ,DSA_RQSTR_DEPT  
               ,GROUP_ID  
               ,ACTIVE_STATUS  
               ,REQ_TYPE  
               ,LAST_LOGED_IN  
               ,CREATED_ID  
         ,CREATED_IP  
         ,CREATED_DATE  
               ,MAKER_ID  
               ,MAKER_IP  
               ,MAKER_DATE  
     ) SELECT DSA_COD  
         ,DSA_NAM  
         ,DSA_CTY  
         ,PRODUCT  
         ,DSA_PHO  
         ,DSA_MOB  
         ,REQUESTOR  
         ,'+@REQUESTOR_DEPT+'
         ,GROUP_ID  
         ,@ACTIVE_STATUS 
         ,1  
         ,LAST_LOG_DAT  
         ,CREATED_ID  
         ,CREATED_IP  
         ,CREATED_DATE  
         ,'+@MAKER_ID+'  
         ,'+@MAKER_IP+'  
         ,GETDATE()  
        FROM DSA_MST WHERE DSA_COD = '+@DSA_CODE+' and ';
    if @REQUESTOR_DEPT = 'N'
    begin
    set @SQL = @SQL + 'REQUESTOR_DEPT is null';
    print('If Query'+@SQL);
    end
    else
    begin
        set @SQL = @SQL + 'REQUESTOR_DEPT = ''' + @REQUESTOR_DEPT + '''';
        print('Else Query'+@SQL);
        end
       --EXEC sp_executesql @SQL, N'@REQUESTOR_DEPT varchar(100) output', @REQUESTOR_DEPT output
    --EXECUTE sp_executesql @SQL;
    execute (@SQL);
    RETURN @ERROR_CODE;  
    END  

    The problem is that you are using dynamic SQL which you should not. Use the
    below instead. Uncomment the query hint if you are worried about
    performance.
    ALTER PROCEDURE [dbo].[S_EDIT_USER]  
    (  @DSA_CODE VARCHAR(10)  
        ,@REQUESTOR_DEPT VARCHAR(40) 
        ,@ACTIVE_STATUS INT  
        ,@MAKER_ID VARCHAR(10)  
        ,@MAKER_IP VARCHAR(20)  
        ,@ERROR_CODE INT OUTPUT  
    AS  
    BEGIN  
    DECLARE @CNT INT;   
    --DECLARE @REQUESTOR_DEPT VARCHAR(40);
    --print(@REQUESTOR_DEPT);
    SELECT @CNT = COUNT(*) FROM TMAS_UAM_USER_TMP WHERE DSA_CODE = @DSA_CODE;  
    IF @CNT > 0  
     SET @ERROR_CODE = 1;  
    ELSE  
     SET @ERROR_CODE = 0; 
    if @REQUESTOR_DEPT = 'N'
     SET @REQUESTOR_DEPT = ''; 
    ELSE  
     SET @REQUESTOR_DEPT = @REQUESTOR_DEPT ; 
     print @REQUESTOR_DEPT;
    IF @ERROR_CODE = 0
    INSERT INTO TMAS_UAM_USER_TMP (  
       DSA_CODE  
               ,DSA_NAME  
               ,DSA_CITY  
               ,DSA_PRODUCT  
               ,DSA_PHNO  
               ,DSA_MOBNO  
               ,DSA_RQSTR  
               ,DSA_RQSTR_DEPT  
               ,GROUP_ID  
               ,ACTIVE_STATUS  
               ,REQ_TYPE  
               ,LAST_LOGED_IN  
               ,CREATED_ID  
         ,CREATED_IP  
         ,CREATED_DATE  
               ,MAKER_ID  
               ,MAKER_IP  
               ,MAKER_DATE  
     ) SELECT DSA_COD  
         ,DSA_NAM  
         ,DSA_CTY  
         ,PRODUCT  
         ,DSA_PHO  
         ,DSA_MOB  
         ,REQUESTOR  
         ,'+@REQUESTOR_DEPT+'
         ,GROUP_ID  
         ,@ACTIVE_STATUS 
         ,1  
         ,LAST_LOG_DAT  
         ,CREATED_ID  
         ,CREATED_IP  
         ,CREATED_DATE  
         ,'+@MAKER_ID+'  
         ,'+@MAKER_IP+'  
         ,GETDATE()  
        FROM DSA_MST
    WHERE DSA_COD = @DSA_CODE
     and  (REQUESTOR_DEPT = @REQUESTOR_DEPT OR @REQUESTOR_DEPT = 'N')
    -- OPTION (RECOMPILE)
    END  
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query in SQL 2008R2 error Msg 1087, Level 15, State 2, Line 31 Must declare the table variable

    Hello Experts, 
    Can You help me; I get the follwing error in my query
    Msg 1087, Level 15, State 2, Line 31
    Must declare the table variable "@ASE_SUBART_GROEP".
    the @ASE_SUBART_GROEP is a self-defined table in this SQL environment.
    Maybe you know the error or the missing part
    Thanks in advance, Jos Dielemans

    I'm not familiar with SAP Business One unfortunately, so can only be of limited help here. But I'm going to guess that @ASE_SUBART_GROEP is a table variable passed to a stored procedure and is defined and passed down by the application, so you won't
    be able to copy-paste this code directly into management studio and get it to work.
    You could remove the join to return *all* records. Although the dataset might be very big
    SELECT T0.CardCode AS 'Klantnr'
    ,T0.CardName AS 'Klantnaam'
    ,T4.GroupName AS 'Klantgroep'
    ,T9.Descr AS 'Merknaam'
    ,T5.SlpName AS 'Verkoper'
    ,T3.MailCity AS 'Leverplaats'
    ,T7.NAME AS 'Leverland'
    ,T3.City AS 'Factuurplaats'
    ,T7.NAME AS 'Factuurland'
    ,T0.DocNum AS 'Documentnr'
    ,T0.DocDate AS 'Datum'
    ,Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) AS 'Jaar'
    ,RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2) AS 'Maand'
    ,(Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) + '-' + RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2)) AS 'Periode'
    ,T1.ItemCode AS 'Artikelnr'
    ,T2.ItemName AS 'Artikelnaam'
    ,T1.Quantity AS 'Aantal VEH'
    ,T2.SVolume AS 'Aantal EH per VEH'
    ,(T1.Quantity * T2.SVolume) AS 'Aantal EH'
    ,T8.UnitName AS 'EH-Naam'
    ,T6.ItmsGrpNam AS 'Artikelgroep'
    ,T2.U_ItemGrp AS 'Hoofdgroep'
    ,T10.NAME AS 'Subgroep'
    ,T1.CogsAcct AS 'Kostpr.rek.'
    ,T1.AcctCode AS 'Opbrengstrek.'
    ,T1.LineTotal AS 'BrutoOmzet'
    ,T0.DiscPrcnt AS 'Korting'
    ,(+ T1.LineTotal * (100 - T0.DiscPrcnt) / 100) AS 'NettoOmzet'
    FROM dbo.OINV T0
    INNER JOIN dbo.INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OCRD T3 ON T0.CardCode = T3.CardCode
    INNER JOIN OCRG T4 ON T3.GroupCode = T4.Groupcode
    INNER JOIN OSLP T5 ON T3.SlpCode = T5.SlpCode
    INNER JOIN OITB T6 ON T2.ItmsGrpCod = T6.ItmsGrpCod
    INNER JOIN OCRY T7 ON T3.Country = T7.Code
    LEFT OUTER JOIN OLGT T8 ON T2.SVolUnit = T8.UnitCode
    LEFT OUTER JOIN UFD1 T9 ON T3.U_ZPgroep = T9.FldValue
    AND TableID = 'OCRD'
    AND FieldID = 2
    --LEFT OUTER JOIN @ASE_SUBART_GROEP T10 ON T2.U_ASE_SUB_ARTGROEP = T10.Code
    WHERE T0.DocDate >= '20120101'
    AND T0.Canceled = 'N'
    UNION ALL
    SELECT T0.CardCode AS 'Klantnr'
    ,T0.CardName AS 'Klantnaam'
    ,T4.GroupName AS 'Klantgroep'
    ,T9.Descr AS 'Merknaam'
    ,T5.SlpName AS 'Verkoper'
    ,T3.MailCity AS 'Leverplaats'
    ,T7.NAME AS 'Leverland'
    ,T3.City AS 'Factuurplaats'
    ,T7.NAME AS 'Factuurland'
    ,T0.DocNum AS 'Documentnr'
    ,T0.DocDate AS 'Datum'
    ,Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) AS 'Jaar'
    ,RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2) AS 'Maand'
    ,(Cast((Datepart(Year, T0.DocDate)) AS VARCHAR) + '-' + RIGHT('00' + CAST(DATEPART(MONTH, T0.DocDate) AS VARCHAR(2)), 2)) AS 'Periode'
    ,T1.ItemCode AS 'Artikelnr'
    ,T2.ItemName AS 'Artikelnaam'
    ,- T1.Quantity AS 'Aantal VEH'
    ,T2.SVolume AS 'Aantal EH per VEH'
    ,(- T1.Quantity * T2.SVolume) AS 'aantal EH'
    ,T8.UnitName AS 'EH-Naam'
    ,T6.ItmsGrpNam AS 'Artikelgroep'
    ,T2.U_ItemGrp AS 'Hoofdgroep'
    ,T10.NAME AS 'Subgroep'
    ,T1.CogsAcct AS 'Kostpr.rek.'
    ,T1.AcctCode AS 'Opbrengstrek.'
    ,- T1.LineTotal AS 'BrutoOmzet'
    ,T0.DiscPrcnt AS 'Korting'
    ,(+ T1.LineTotal * (100 - T0.DiscPrcnt) / 100) AS 'NettoOmzet'
    FROM dbo.ORIN T0
    INNER JOIN dbo.RIN1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OCRD T3 ON T0.CardCode = T3.CardCode
    INNER JOIN OCRG T4 ON T3.GroupCode = T4.Groupcode
    INNER JOIN OSLP T5 ON T3.SlpCode = T5.SlpCode
    INNER JOIN OITB T6 ON T2.ItmsGrpCod = T6.ItmsGrpCod
    INNER JOIN OCRY T7 ON T3.Country = T7.Code
    LEFT OUTER JOIN OLGT T8 ON T2.SVolUnit = T8.UnitCode
    LEFT OUTER JOIN UFD1 T9 ON T3.U_ZPgroep = T9.FldValue
    AND TableID = 'OCRD'
    AND FieldID = 2
    --LEFT OUTER JOIN @ASE_SUBART_GROEP T10 ON T2.U_ASE_SUB_ARTGROEP = T10.Code
    WHERE T0.DocDate >= '20120101'
    AND T0.Canceled = 'N'
    ORDER BY T0.CardCode
    The join to the table variable has been commented out above, so the code should run. After that you might want to update the WHERE clause to include only particular sub-groups

  • Where is it declared the return variable?

    Hi everyone,
    please which system privileges must you have to recompile a stored procedure owned by another application developer?
    and where is it declared the return variable?
    thank you

    In short you will need ALTER ANY PROCEDURE privilidge for that.
    Lets do a test for this:
    From User A:
    SQL> create table test as select * from user_objects where rownum<10;
    SQL> create procedure test_proc as
    2 begin
    3 delete test;
    4 commit;
    5 end;
    6 /
    Procedure created.
    Now from User Scott:
    alter procedure cr.test_proc compile
    ERROR at line 1:
    ORA-01031: insufficient privileges
    Now connect to user A and do the following:
    1* grant alter any procedure to scott
    SQL> /
    Grant succeeded.
    Now from Scott user:
    alter procedure cr.test_proc compile;
    Procedure altered.
    SQL> show errors
    No errors.
    Thats what you wanted.
    Riaz

  • In Dreamweaver MySites[New Site] menu option , if I had a hosting JSP/PHP what I must declare the hosting JSP or PHP ?

    In Dreamweaver MySites[New Site] menu option , if I had a hosting JSP/PHP what I must declare the hosting JSP or PHP ?

    The simplest answer is to choose the language you work best with, and that fits the clients specification the best.
    I have mixed server languages on a site before, (would not recommend) when a client has decided they wish to change from their old one to a new(er) /different one, the only thing you must watch if doing this, is that you do not mix languages on the same page (will not work correctly, if at all), and parameter passing.
    PZ

  • How do I declare the extra variable?

    List the customer number, name, (first and last), order number, order date, employee number, employee, name (first and last), product number, product name, and order cost, (orderline.qty*prodprice) for products ordered on January 23, 2009
    I have no column called order cost in any tables. How do I declare a new variable called order cost in the query? And to date line is missing a right parenthesis. The exact line worked with a different question but accept that I have added on the date in this line.
    SELECT C.CUSTNO, C.CUSTFIRSTNAME, C.CUSTLASTNAME, O.ORNO, O.ORDDATE, E.EMPNO, E.EMPFIRSTNAME, E.EMPLASTNAME, P.PRODNO, P.PRODNAME, L.PRODNO, L.QTY, Order_cost
    From Customer c, Orders o, ORDERLINE L, Employee e, Product P
    where(C.CUSTNO=O.CUSTNO) and(O.EMPNO = E.EMPNO) and (O.ORDNO = L.ORDNO) and (P.PRODNO = L.PRODNO) and Order_cost= (L.QTY*ProdPrice)
    and (o.OrdDate >= to_date('23/01/2009', 'dd/'mm/yyyy') and o.OrdDate <= add_months(to_date('23/01/2009','dd/'mm/yyyy'),+1)-1);
    Thanks.

    Hi,
    user9164240 wrote:
    List the customer number, name, (first and last), order number, order date, employee number, employee, name (first and last), product number, product name, and order cost, (orderline.qty*prodprice) for products ordered on January 23, 2009
    I have no column called order cost in any tables. How do I declare a new variable called order cost in the query? And to date line is missing a right parenthesis. The exact line worked with a different question but accept that I have added on the date in this line.
    SELECT C.CUSTNO, C.CUSTFIRSTNAME, C.CUSTLASTNAME, O.ORNO, O.ORDDATE, E.EMPNO, E.EMPFIRSTNAME, E.EMPLASTNAME, P.PRODNO, P.PRODNAME, L.PRODNO, L.QTY, Order_cost
    From Customer c, Orders o, ORDERLINE L, Employee e, Product P
    where(C.CUSTNO=O.CUSTNO) and(O.EMPNO = E.EMPNO) and (O.ORDNO = L.ORDNO) and (P.PRODNO = L.PRODNO) and Order_cost= (L.QTY*ProdPrice)
    and (o.OrdDate >= to_date('23/01/2009', 'dd/'mm/yyyy') and o.OrdDate <= add_months(to_date('23/01/2009','dd/'mm/yyyy'),+1)-1);Never write, let alone post, unformatted code.
    Format your code so that it's easy to see (among other things) that
    (1) the arguments to TO_DATE match each other, and
    (2) parentheses are balanced.
    For example:
    SELECT      C.CUSTNO
    ,      C.CUSTFIRSTNAME
    ,      C.CUSTLASTNAME
    ,      O.ORNO
    ,      O.ORDDATE
    ,      E.EMPNO
    ,     E.EMPFIRSTNAME
    ,     E.EMPLASTNAME
    ,     P.PRODNO
    ,     P.PRODNAME
    ,     L.PRODNO
    ,     L.QTY
    ,     L.QTY * ProdPrice     AS Order_cost
    From      Customer     c
    ,     Orders           o
    ,     ORDERLINE     L
    ,     Employee     e
    ,     Product          P
    where     (C.CUSTNO     = O.CUSTNO)
    and     (O.EMPNO      = E.EMPNO)
    and      (O.ORDNO      = L.ORDNO)
    and      (P.PRODNO      = L.PRODNO)
    and      (o.OrdDate      >= to_date ( '23/01/2009'
                           , 'dd/'mm/yyyy'          -- WRONG!  Look at alignment
    and      o.OrdDate      <= add_months ( to_date ( '23/01/2009'
                                  , 'dd/'mm/yyyy'     -- WRONG!  Look at alignment
                              , +1
                              ) -1
    )                    -- Extra right parentheses
    ;When you post formatted text on this site, type these 6 characters
    \(all small letters, inside curly brackets) before and after each section of formatted text.  If you don't, this site will not show all the extra spaces.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Stored Proc with SSRS multi value parameter gives " Must Declare scalar Varaiable @StateID

    Hi All,
    I have one stored proc with @fromDate , @Todate and multivalue input
    parameter@StateID of type integer.
    When I run below stored proc via SSRS by selecting multiple values thru multiValue parameter into @StateID...it gives error saying "Must Declare scalar variable @StateID"
    Not sure what is wrong with the input parameters.
    ID is Integer type in all the 3 tables - dbo.EastCities, dbo.WestCities  , dbo.Country
    I need help fixing this  "Must Declare scalar variable @StateID" error
    This is the UDF split() I am using..
    Function:
    CREATE FUNCTION dbo.SplitStateID
    (    @List VARCHAR(MAX))
    RETURNS TABLE
    AS   
    RETURN   
    (        SELECT DISTINCT [Value] = CONVERT(INT, LTRIM(RTRIM(CONVERT( VARCHAR(12),SUBSTRING(@List, Number, CHARINDEX(',', @List + ',', Number) - Number))))
     FROM  dbo.Numbers       
     WHERE Number <= CONVERT(INT, LEN(@List))AND SUBSTRING(',' + @List, Number, 1) = ','    );
     GO
     SELECT [Value] FROM dbo.SplitStateID('10,30,50');
    Also, I have created dbo.Numbers table which is used in udf..
    reference url -- > 
    http://sqlblog.com/blogs/aaron_bertrand/archive/2009/08/01/processing-a-list-of-integers-my-approach.aspx
    SET NOCOUNT ON;
    DECLARE @UpperLimit INT;
    SET @UpperLimit = 10000;
    WITH n AS(   
    SELECT        rn = ROW_NUMBER() OVER        (ORDER BY s1.[object_id])   
    FROM sys.objects AS s1   
    CROSS JOIN sys.objects AS s2   
    CROSS JOIN sys.objects AS s3)
    SELECT [Number] = rn - 1
    INTO dbo.Numbers FROM n
    WHERE rn <= @UpperLimit + 1;
    CREATE UNIQUE CLUSTERED INDEX n ON dbo.Numbers([Number]);
    Stored procedure:
    Create Procedure dbo.CountrySelection
    ( @FromDate Date, @ToDate Date, @StateID Int)
    AS
    BEGIN
    set nocount on;
    SELECT * INTO #EastCities
    FROM (
    SELECT ID,Description from dbo.EastCities
    Where ID IN (SELECT Value from dbo.SplitStateID(@StateID))
    ) AS A
    SELECT * INTO #WestCities
    FROM (
    SELECT ID,Description from dbo.WestCities
    Where ID IN (SELECT Value from dbo.SplitStateID(@StateID))
    ) AS B
    SELECT * INTO #Country
    FROM (
    SELECT ID , Description, State,Country From dbo.Country
    ) AS C
    SELECT EC.ID AS East, WC.ID AS West , EC.Description AS EastDesc, WC.Description AS WestDesc, CT.State, CT.Country
    FROM #Country CT
    LEFT JOIN #EastCities EC ON CT.ID=EC.ID
    LEFT JOIN #WestCities WC ON CT.ID=WC.ID
    DROP TABLE #EastCities
    DROP TABLE #WestCities
    DROP TABLE #Country
    END
    Above 3 temp tables are joined by #Country.ID key
    It works fine when single value is passed in @StateID
    Exec dbo.CountrySelection '01/01/2010','02/01/2010',10
    It fails when multi value passed into @StateID
    Exec dbo.CountrySelection '01/01/2010','02/01/2010','10,30,40'
    SSRS error log shows "Must declare scalar variable @StateID"
    Need help in fixing this issue.
    Thanks,
    RH
    sql

    Visakh,
    I changed @StateID date type to varchar(max) and still I get this error.  
    System.Data.SqlClient.SqlException: Must declare the scalar variable "@StateID".
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
    I am running this SO in SSRS quert Type =Text
    Actually sp created on db2 database and due to some limitations I am running(via SSRS) this from different db1 database data source within the same db server. When I run this sp from SSRS query designer(edit query designer button) and pass
    multivalue parameters to @StateID as 10 , 20 it works and gives expected resultset.
    Thanks,
    RH
    sql

  • Why do we declare the variables private in a bean

    Hi,
    when we create a bean in the MVC architecture why do we declare the variables private. Also when do we use the access specifier private.
    Regards,
    Prashant

    pksingh79 wrote:
    Hi ^^,
    thanks for replying.I had a discussion with one of my trainers and he was of the opinion that the variables should generally be declared private. In this way we prevent classes from accessing and setting illegal values to those variables.
    Say for instance we have the class person as follows:
    public class Person
    int age;
    setAge(int age)
    if (age < 0)
    return null
    Person p = new Person() ;
    p.age = -2;
    //this would be perfectly legal
    //where as if we declare the variable as private as follows:
    public class Person
    private int age;
    setAge(int age)
    if (age < 0)
    return null
    Person p = new Person() ;
    // P.age = -2;   this would be illegal as age is private and would have to be accessed by the method defined above.
    p.setAge(-2);
    //the cbove line would retun null values.
    public class Person {
        private int age;
        public void setAge(int age) {
            if (age < 0) {
                throw new IllegalArgumentException("...");
            this.age = age;
    }

  • LabVIEW could not generate code for the shared variable.You must open the VI in the project that contains the library where the shared variable resides

    HI
    When I put a network shared variable with fifo RT activated on my diagram, the arrow is broken.and I' ve got this message:
    ""LabVIEW could not generate code for the shared variable.You must open the VI in the project that contains the library where the shared variable resides""
    If I uncheck FIFO RT option for this variable the arrow isn't broken anymore.
    I 've no idea how to correct this weird error?
    Autodeploy is on, and I've check copy / delete in diagram in tool/options\diagram
    regards,
    james

    Hello,
    I don't reproduce this error.
    Could you send your VI?
    Regards
    VéroniqueD
    NI France

  • Passing the sh variable value to input of  to Pl/SQL Procedure

    Hi All,
    My doubt is how can I pass the sh variable (.i.e file name stored in sh variable called($F)) as a input of below mention procedure (YODEL_XL_INS_SDG_COMMER_PROD)
    for F in *.dat; do
    echo $F
    #sqlldr apps/apps control=$CONTROL data=$F
    # Below Part is used for Add the file name into table
    cat $CONTROL| sed "s/:FILE/$F/g" > $F.ctl
    sqlldr apps/apps control=$F.ctl log=$F.log bad=$F.bad discard=$DISCARD data=$F
    sqlplus -s apps/apps << EOF
    spool Yodel_xl_om_inven_items_pkg.txt
    set serveroutput on;
    DECLARE
    X_Error_Code VARCHAR2(1000);
    X_Error_Message VARCHAR2(1000);
    X_Status VARCHAR2(1000);
    BEGIN
         YODEL_XL_INS_SDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    END;
    SHOW ERRORS;
    spool off;
    exit
    EOFDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    If i'm passing directly then getting below error.
    YODEL_XL_INS_SDG_COMMER_PROD(SDG_Testing_produsts3.dat,'SDG',X_Status,X_Error_Code,X_Error_Message);
    ERROR at line 8:
    ORA-06550: line 8, column 66:
    PLS-00201: identifier 'SDG_Testing_produsts3.dat' must be declared
    ORA-06550: line 8, column 2:
    PL/SQL: Statement ignored
    No errors.
    Could you please help me to resolve this.
    Edited by: user9077611 on 30-Aug-2012 10:11

    user9077611 wrote:
    Hi All,
    My doubt is how can I pass the sh variable (.i.e file name stored in sh variable called($F)) as a input of below mention procedure (YODEL_XL_INS_SDG_COMMER_PROD)
    for F in *.dat; do
    echo $F
    #sqlldr apps/apps control=$CONTROL data=$F
    # Below Part is used for Add the file name into table
    cat $CONTROL| sed "s/:FILE/$F/g" > $F.ctl
    sqlldr apps/apps control=$F.ctl log=$F.log bad=$F.bad discard=$DISCARD data=$F
    sqlplus -s apps/apps << EOF
    spool Yodel_xl_om_inven_items_pkg.txt
    set serveroutput on;
    DECLARE
    X_Error_Code VARCHAR2(1000);
    X_Error_Message VARCHAR2(1000);
    X_Status VARCHAR2(1000);
    BEGIN
         YODEL_XL_INS_SDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    END;
    SHOW ERRORS;
    spool off;
    exit
    EOFDG_COMMER_PROD($F,'SDG',X_Status,X_Error_Code,X_Error_Message);
    If i'm passing directly then getting below error.
    YODEL_XL_INS_SDG_COMMER_PROD(SDG_Testing_produsts3.dat,'SDG',X_Status,X_Error_Code,X_Error_Message);
    ERROR at line 8:
    ORA-06550: line 8, column 66:
    PLS-00201: identifier 'SDG_Testing_produsts3.dat' must be declared
    ORA-06550: line 8, column 2:
    PL/SQL: Statement ignored
    No errors.
    Could you please help me to resolve this.
    Edited by: user9077611 on 30-Aug-2012 10:11You know that strings should be enclosed in single quote marks.
    Right?

  • Unable to Declare a Temporary Variable in Calc Script

    We are using Hyperion System 9 BI+ Analytic Administration Services. 9.2.03.0.44
    I am trying to declare a temporary variable in a calculation script.
    We have found several guides and examples in the support documentation that give us a step by step instruction on how to 1.) declare the variable, then 2.) Assign a value.
    Example:
    /* Declare the variable */
    VAR TotalAllocDept;
    /* Baseline Fix */
    FIX ("FY10","Jan","BU Version_1", "Actual", "NoProd", "NoCust")
    /* Assign a value to the variable */
    TotalAllocDept = ("Alloc_HR"+"Alloc_IT"+"Alloc_FIN");
    ENDFIX
    /* Allocate overhead based on Total Alloc Dept Variable */
    FIX ("FY10","Jan","BU Version_1", "Actual", "NoProd", "NoCust")
    "Alloc_5xSS" = @ALLOCATE("Alloc_Overhead","Account", TotalAllocDept,, share);
    ENDFIX
    However, when we try to check the syntax, we are given various error messages such as:
    Error parsing FIX STATEMENT "invalid object type" and
    "Invalid member name" and
    Invalid Calc Script syntax.
    Can anyone suggest some techniques that we can try or alternative ways of entering the text to make it possible for us to use temporary variables?

    A variable must be declared within a calc member block and can only exist for the scope of that block.
    This would work (not that you would necessarily want it)"
    /* Allocate overhead based on Total Alloc Dept Variable */
    FIX ("FY10","Jan","BU Version_1", "Actual", "NoProd", "NoCust")
    "Alloc_5xSS"
    TotalAllocDept = ("Alloc_HR""Alloc_IT""Alloc_FIN");
    "Alloc_5xSS" = @ALLOCATE("Alloc_Overhead","Account", TotalAllocDept,, share);
    ENDFIX
    Regards,
    Cameron Lackpour

Maybe you are looking for