Skip to Content
J S

Query not working

Hi

Error - 1). [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a  2). [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ','. 3). [Microsoft][SQL Server Native Client 11.0][SQL Server]Statement 'User-Defined Values' (CSHS) (s) could not be prepared.



/* SELECT FROM [dbo].[OWHS] T0 */
DECLARE @Whse AS nvarchar(10)
/* WHERE */
SET @Whse = /* T0.WhsCode */ '[%0]'

with CTE_A1 as
(
    Select 
        A.BatchNum as Batchnum,B.ItemCode as ItemCode,
        B.ItemName as ItemName,A.WhsCode as Whscode,(Select AvgPrice from OITW where ItemCode = A.ItemCode And WhsCode = A.WhsCode) as Price,
        (Select InDate from OBTN where DistNumber = A.BatchNum and ItemCode = b.ItemCode) as DocDate
    from IBT1 A
    Inner Join OITM B on A.ItemCode = B.ItemCode
    where A.WhsCode =  @Whse
)
select * from cte_A1

Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 30, 2020 at 02:19 AM

    Hello,

    The parameter fetching has issue your query try the below:

    DECLARE @Whse AS nvarchar(10)
    
    SET @Whse =  (Select  A.WhsCode From OWHS A Where A.WhsCode='[%0]') 
    
    Select   A.BatchNum as Batchnum,B.ItemCode as ItemCode,  B.ItemName as ItemName,A.WhsCode as Whscode,(Select AvgPrice from OITW where ItemCode = A.ItemCode And WhsCode = A.WhsCode) as Price,  (Select InDate from OBTN where DistNumber = A.BatchNum and ItemCode = b.ItemCode) as DocDate  from IBT1 A  Inner Join OITM B on A.ItemCode = B.ItemCode  where A.WhsCode =  @Whse

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.