日期:2014-05-17 浏览次数:20548 次
SELECT (SELECT sum(nqhje) FROM t_qhb WHERE
CONVERT(datetime,srq,112)BETWEEN dateadd(dd,-15,@jk) AND @jk)
/
(SELECT sum(nchje) FROM t_chb WHERE
CONVERT(datetime,srq,112)BETWEEN dateadd(dd,-15,@jk) AND @jk) AS 节前15天缺货率
,
(SELECT sum(nqhje) FROM t_qhb WHERE
CONVERT(datetime,srq,112)BETWEEN @jj AND dateadd(dd,15,@jj))
/
(SELECT sum(nchje) FROM t_chb WHERE
CONVERT(datetime,srq,112)BETWEEN @jj AND dateadd(dd,15,@jj)) AS 节后15天缺货率
,
(SELECT sum(nqhje) FROM t_qhb WHERE
CONVERT(datetime,srq,112)BETWEEN dateadd(dd,-15,@jk) AND dateadd(dd,15,@jj))
/
(SELECT sum(nchje) FROM t_chb WHERE
CONVERT(datetime,srq,112)BETWEEN dateadd(dd,-15,@jk) AND dateadd(dd,15,@jj)) AS 前后30天缺货率
DECLARE @qk datetime,@jk datetime
,@qj datetime,@jj datetime
,@str_jk VARCHAR(10),@str_jj VARCHAR(10)
SET @qk='2011-06-21'
SET @jk='2012-06-21'
SET @qj='2011-06-23'
SET @jj='2012-06-22'
SET @str_jk=CONVERT(VARCHAR(10),@jk,120)
SET @str_jj=CONVERT(VARCHAR(10),@jj,120)
DECLARE @WHERE1 NVARCHAR(MAX),@WHERE2 NVARCHAR(MAX),@WHERE3 NVARCHAR(MAX)
SELECT @WHERE1='CONVERT(datetime,srq,112)BETWEEN dateadd(dd,-15,'''+@str_jk+''') AND '''+@str_jk+'''' ,
@WHERE2='CONVERT(datetime,srq,112) BETWEEN '''+@str_jj+''' AND dateadd(dd,15,'''+@str_jj+''')' ,
@WHERE3='CONVERT(datetime,srq,112) BETWEEN dateadd(dd,-15,'''+@str_jk+''') AND dateadd(dd,15,'''+@str_jj+''')
(SELECT (SELECT sum(nqhje) FROM t_qhb WHERE CONVERT(datetime,srq,112)BETWEEN @jk AND @jj
AND sspbh NOT IN (SELECT b.GDGID FROM t_ord a,t_orddtl b WHERE a.fildate BETWEEN @jk
AND @jj AND a.num=b.num))
/
(SELECT sum(nchje) FROM t_chb WHERE CONVERT(datetime,srq,112)BETWEEN @jk AND @jj
AND sspbh NOT IN (SELECT b.GDGID FROM t_ord a,t_orddtl b WHERE a.fildate BETWEEN @jk
AND @jj AND a.num=b.num)) AS 不订货缺货率) g