Skip to Content
0
J S
Jul 29, 2020 at 04:27 PM

Query not working

79 Views Last edit Jul 29, 2020 at 05:28 PM 3 rev

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