DECLARE @db AS VARCHAR(20)
SET @db = 'marda_test'
SELECT t1.[ItemCode]
, t1.[U_FBC]
, t1.[U_FBD]
, t1.[U_FDC]
, t1.[U_FDD]
, t1.[U_CC]
, t1.[U_CD]
, t1.[U_PTC]
, t1.[U_PTD]
, t1.[U_CLRCODE]
, t1.[U_CLRD]
, t1.[U_SC]
, t1.[U_SD]
, t1.[U_SESC]
, t1.[U_SESD]
, t1.[U_FC]
, t1.[U_FD]
, t1.[U_STLCODE]
, t1.[U_STLDESC]
, t1.[U_PPO]
, t1.[U_MG]
, t1.[U_BC]
, t1.[U_BD]
, t1.[U_PC]
, t1.[U_PD]
, t1.[U_SLV]
, t1.[U_COLORC]
, t1.[U_COLORD]
, t1.[ItemCode]
, t1.create_date
FROM oitm_Clone T0, OITM T1
WHERE T0.itemcode = T1.itemcode
AND @db = '1'
AND t1.create_date = T0.createdate
AND t0.U_slv IS NOT NULL
问问题
76 次
2 回答
0
我猜你可以使用存储过程。
于 2013-09-06T05:48:39.853 回答
0
试试这个——
CREATE PROCEDURE dbo.usp_test1
@db AS VARCHAR(20)
AS BEGIN
SELECT *
FROM OITM T1
WHERE @db = '1' -- 'marda_test' != '1'
AND EXISTS(
SELECT 1
FROM oitm_Clone T0
WHERE T0.itemcode = T1.itemcode
AND T1.create_date = T0.createdate
AND T0.U_slv IS NOT NULL
)
END
GO
EXEC usp_test1 @db = 'marda_test'
于 2013-09-06T06:34:27.670 回答