Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 7856

[Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string. 'User-Defined Values' (CSHS)

$
0
0

Dear All

 

I wrote a query in B1 and call a stored procedure

 

/* Select from [dbo].[OJDT] Tx */

declare @ToDate as datetime

declare @EndDate as datetime

/* WHERE */

set @ToDate = /* Tx.RefDate */ '[%0]'

set @EndDate = /* Tx.RefDate */ '[%1]'

exec ZPL.dbo.consol_byitemdetail @ToDate, @EndDate

 

ALTER Procedure [dbo].[consol_byitemdetail]

@ToDate Datetime ,

@EndDate Datetime

as

BEGIN

declare @tempdate datetime

declare @temp varchar(MAX)

 

set @tempdate = convert(datetime, @ToDate)

 

  while (left(convert(char,@tempdate,120),7)<= left(convert(char,@EndDate,120),7))

  BEGIN

 

  set @temp=@temp+'

  insert into @SALESDETAIL(ITEMNAME,SERIES, PRODUCTLINE, PROGROUP ,['+RTRIM(left(convert(char,@tempdate,120),7))+'-Qty'+']

  select T000.itemname, T000.U_series, T000.U_productline, T000.U_progroup,

  sum(T000.jqty) as ''Qty''

  from (

select T0.itemname, T0.U_series, T0.U_productline, T0.U_progroup ,

  (select isnull(SUM(T01.quantity),0) from zreport.dbo.OINV4recon T00 inner join zreport.dbo.INV1 T01 on T00.DocEntry = T01.DocEntry AND T00.DB = T01.DB where (T00.DocDate >= convert(datetime,'+@tempdate+',5)) AND (T00.DocDate <= dateadd(day,-1,(dateadd(month, 1,convert(datetime,'+@tempdate+',5))))) and T01.Itemcode=T0.Itemcode and T01.DB=T0.DB)-

  (select isnull(sum(T01.quantity),0) from zreport.dbo.RIN1 T01 inner join zreport.dbo.ORIN T00 on T00.docentry=T01.docentry AND T00.DB = T01.DB where T00.DocDate >= convert(datetime,'+@tempdate+',5) AND T00.DocDate <= dateadd(day,-1,(dateadd(month, 1,convert(datetime,'+@tempdate+',5)))) and T01.Itemcode=T0.Itemcode and T01.DB=T0.DB)  as ''jqty''

from zreport.dbo.oitm T0) T000

  group by T000.itemname, T000.U_series, T000.U_productline, T000.U_progroup

  )'

End

 

B1 shows those error message

1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.  'User-Defined Values' (CSHS)

 

if I run the above sql without using the @tempdate, and use '01/01/2014', it can show total qty in January 2014 (AR invoice and AR credit memo).

 

Regards

Edmund


Viewing all articles
Browse latest Browse all 7856

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>