DECLARE @PR棜楌No int
DECLARE @彜昳No int
DECLARE @屭媞No int
DECLARE @搊榐僗僞僢僼No int
DECLARE @峀崘No int
DECLARE @僾儘儌乕僔儑儞梊掕No int
DECLARE @僾儘儌乕僔儑儞幚愌No int
DECLARE @PR嬫暘No int
DECLARE @憤旓梡 int
DECLARE @懳徾彜昳憤悢 int
DECLARE @懳徾婛懚屭媞憤悢 int
DECLARE @桳岠擔悢撪偺憤攧忋 int
DECLARE @怴婯屭媞妉摼悢 int
DECLARE @尒崬屭媞妉摼悢 int
DECLARE @孈婲偟屭媞悢 int
DECLARE @峏怴僗僞僢僼No int
DECLARE @擭 int
DECLARE @擭寧 int
DECLARE @寧 int
DECLARE @R int
DECLARE @F int
DECLARE @M int
DECLARE @G int
DECLARE @B int
DECLARE @僐儞僞僋僩棜楌No int
DECLARE @僶僂儞僪No int
DECLARE @僣乕儖No int
DECLARE @僐儞僞僋僩僗僞僢僼No int
DECLARE @僗僞僢僼No int
DECLARE @栶怑No int
DECLARE @尃尷No int
DECLARE @夋柺No int
DECLARE @嬫暘 int
DECLARE @壜晄壜 int
DECLARE @惈暿 int
DECLARE @儊儖儅僈嫋戻 int
DECLARE @壠懓峔惉No int
DECLARE @壠懓嬫暘 int
DECLARE @曗懌柤No int
DECLARE @屭媞曗懌No int
DECLARE @峸擖嵪傒彜昳No1 int
DECLARE @峸擖嵪傒彜昳No2 int
DECLARE @峸擖嵪傒彜昳No3 int
DECLARE @RFM儔儞僋 int
DECLARE @RFM庬暿 int
DECLARE @儔儞僋 int
DECLARE @斕攧悢 int
DECLARE @彜昳扨壙 int
DECLARE @尦彜昳No int
DECLARE @摦岦No int
DECLARE @斕攧棜楌No int
DECLARE @嵟戝斕攧嬥妟椵寁 int
DECLARE @斕攧屄悢 int
DECLARE @懳徾寧 int
DECLARE @斕攧嬥妟 int
DECLARE @PR柤 varchar
DECLARE @峀崘柤 varchar
DECLARE @撪梕 varchar
DECLARE @扴摉幰柤 varchar
DECLARE @TEL varchar
DECLARE @FAX varchar
DECLARE @儊乕儖傾僪儗僗 varchar
DECLARE @URL varchar
DECLARE @旛峫 varchar
DECLARE @憖嶌抂枛柤 varchar
DECLARE @憖嶌僗僞僢僼巵柤 varchar
DECLARE @憖嶌夋柺 varchar
DECLARE @憖嶌撪梕 varchar
DECLARE @審柤 varchar
DECLARE @杮暥 varchar
DECLARE @僗僞僢僼ID varchar
DECLARE @僷僗儚乕僪 varchar
DECLARE @巵柤 varchar
DECLARE @抣 varchar
DECLARE @屭媞ID varchar
DECLARE @巵柤僇僫 varchar
DECLARE @梄曋斣崋 varchar
DECLARE @廧強 varchar
DECLARE @曗懌撪梕 varchar
DECLARE @彜昳ID varchar
DECLARE @彜昳柤 varchar
DECLARE @岞奐梊掕擔 datetime
DECLARE @岞奐幚巤擔 datetime
DECLARE @梊掕婜娫fr datetime
DECLARE @梊掕婜娫to datetime
DECLARE @岞奐梊掕擔fr datetime
DECLARE @岞奐梊掕擔to datetime
DECLARE @岞奐幚巤擔fr datetime
DECLARE @岞奐幚巤擔to datetime
DECLARE @幚巤婜娫fr datetime
DECLARE @幚巤婜娫to datetime
DECLARE @媥柊懳徾擔 datetime
DECLARE @斕攧擔帪fr datetime
DECLARE @斕攧擔帪to datetime
DECLARE @憖嶌擔fr datetime
DECLARE @憖嶌擔to datetime
DECLARE @僐儞僞僋僩擔帪 datetime
DECLARE @惗擭寧擔 datetime
DECLARE @寁嶼懳徾奐巒擔帪 datetime
DECLARE @寁嶼懳徾廔椆擔帪 datetime
DECLARE @斕攧擔帪 datetime
DECLARE @斕攧擔fr datetime
DECLARE @斕攧擔to datetime
DECLARE @斕攧擔帪From datetime

SET @PR棜楌No = 1
SET @彜昳No = 1
SET @屭媞No = 1
SET @搊榐僗僞僢僼No = 1
SET @峀崘No = 1
SET @僾儘儌乕僔儑儞梊掕No = 1
SET @僾儘儌乕僔儑儞幚愌No = 1
SET @PR嬫暘No = 1
SET @憤旓梡 = 1
SET @懳徾彜昳憤悢 = 1
SET @懳徾婛懚屭媞憤悢 = 1
SET @桳岠擔悢撪偺憤攧忋 = 1
SET @怴婯屭媞妉摼悢 = 1
SET @尒崬屭媞妉摼悢 = 1
SET @孈婲偟屭媞悢 = 1
SET @峏怴僗僞僢僼No = 1
SET @擭 = 1
SET @擭寧 = 1
SET @寧 = 1
SET @R = 1
SET @F = 1
SET @M = 1
SET @G = 1
SET @B = 1
SET @僐儞僞僋僩棜楌No = 1
SET @僶僂儞僪No = 1
SET @僣乕儖No = 1
SET @僐儞僞僋僩僗僞僢僼No = 1
SET @僗僞僢僼No = 1
SET @栶怑No = 1
SET @尃尷No = 1
SET @夋柺No = 1
SET @嬫暘 = 1
SET @壜晄壜 = 1
SET @惈暿 = 1
SET @儊儖儅僈嫋戻 = 1
SET @壠懓峔惉No = 1
SET @壠懓嬫暘 = 1
SET @曗懌柤No = 1
SET @屭媞曗懌No = 1
SET @峸擖嵪傒彜昳No1 = 1
SET @峸擖嵪傒彜昳No2 = 1
SET @峸擖嵪傒彜昳No3 = 1
SET @RFM儔儞僋 = 1
SET @RFM庬暿 = 1
SET @儔儞僋 = 1
SET @斕攧悢 = 1
SET @彜昳扨壙 = 1
SET @尦彜昳No = 1
SET @摦岦No = 1
SET @斕攧棜楌No = 1
SET @嵟戝斕攧嬥妟椵寁 = 1
SET @斕攧屄悢 = 1
SET @懳徾寧 = 1
SET @斕攧屄悢 = 1
SET @斕攧嬥妟 = 1
SET @PR柤 = 'a'
SET @峀崘柤 = 'a'
SET @撪梕 = 'a'
SET @扴摉幰柤 = 'a'
SET @TEL = 'a'
SET @FAX = 'a'
SET @儊乕儖傾僪儗僗 = 'a'
SET @URL = 'a'
SET @旛峫 = 'a'
SET @憖嶌抂枛柤 = 'a'
SET @憖嶌僗僞僢僼巵柤 = 'a'
SET @憖嶌夋柺 = 'a'
SET @憖嶌撪梕 = 'a'
SET @審柤 = 'a'
SET @杮暥 = 'a'
SET @僗僞僢僼ID = 'a'
SET @僷僗儚乕僪 = 'a'
SET @巵柤 = 'a'
SET @抣 = 'a'
SET @屭媞ID = 'a'
SET @巵柤僇僫 = 'a'
SET @梄曋斣崋 = 'a'
SET @廧強 = 'a'
SET @彜昳ID = 'a'
SET @彜昳柤 = 'a'
SET @岞奐梊掕擔 = '2002/1/11'
SET @岞奐幚巤擔 = '2002/1/11'
SET @幚巤婜娫fr = '2002/1/11'
SET @幚巤婜娫to = '2003/7/11'
SET @媥柊懳徾擔 = '2001/7/15'
SET @梊掕婜娫fr = '2001/7/15'
SET @梊掕婜娫to = '2001/7/15'
SET @岞奐梊掕擔fr = '2002/1/11'
SET @岞奐梊掕擔to = '2002/1/11'
SET @岞奐幚巤擔fr = '2002/1/11'
SET @岞奐幚巤擔to = '2002/1/11'
SET @斕攧擔帪fr = '2002/1/11'
SET @斕攧擔帪to = '2002/1/11'
SET @憖嶌擔fr = '2002/1/11'
SET @憖嶌擔to = '2002/1/11'
SET @僐儞僞僋僩擔帪 = '2002/1/11'
SET @惗擭寧擔 = '2002/1/11'
SET @寁嶼懳徾奐巒擔帪 = '2002/1/11'
SET @寁嶼懳徾廔椆擔帪 = '2002/1/11'
SET @斕攧擔帪 = '2002/1/11'
SET @斕攧擔fr = '2002/1/11'
SET @斕攧擔to = '2002/1/11'
SET @斕攧擔帪From = '2002/1/11'



---- Fill
--SELECT
--	0 AS 怴婯, 
--	0 AS 曄峏, 
--	0 AS 嶍彍, 
--	慻怐No,
--	斕攧棜楌No, 
--	斕攧擔帪, 
--	彜昳ID, 
--	彜昳柤, 
--	彜昳扨壙, 
--	斕攧屄悢, 
--	屭媞ID, 
--	彜昳No, 
--	屭媞No
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No
SELECT
	0 AS 怴婯, 
	0 AS 曄峏, 
	0 AS 嶍彍, 
	斕攧棜楌No,
	斕攧擔帪,
	彜昳ID, 
	彜昳柤,
	彜昳扨壙,
	斕攧屄悢,
	屭媞ID,
	彜昳No,
	屭媞No
FROM
	H01斕攧棜楌


---- Delete
--DELETE FROM H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧棜楌No = @斕攧棜楌No
DELETE FROM H01斕攧棜楌
WHERE
	(斕攧棜楌No = @斕攧棜楌No)


---- DeleteALL
--DELETE FROM H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No
DELETE FROM H01斕攧棜楌


---- FillBy専嶕
--SELECT
--	 慻怐No
--	,斕攧棜楌No
--	,斕攧擔帪
--	,彜昳ID
--	,彜昳柤
--	,彜昳扨壙
--	,斕攧屄悢
--	,屭媞ID
--	,彜昳No
--	,屭媞No
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧擔帪 >= @斕攧擔fr AND 
--	斕攧擔帪 <= @斕攧擔to AND 
--	((@彜昳ID IS NULL) OR (彜昳ID LIKE '%' + @彜昳ID + '%')) AND 
--	((@彜昳柤 IS NULL) OR (彜昳柤 LIKE '%' + @彜昳柤 + '%')) AND 
--	((@彜昳扨壙 IS NULL) OR (彜昳扨壙 = @彜昳扨壙)) AND 
--	((@屭媞ID IS NULL) OR (屭媞ID LIKE '%' + @屭媞ID + '%'))
SELECT TOP 100000
	斕攧棜楌No,
	斕攧擔帪,
	彜昳ID,
	彜昳柤,
	彜昳扨壙,
	斕攧屄悢,
	屭媞ID,
	彜昳No, 
	屭媞No
FROM
	H01斕攧棜楌
WHERE
	斕攧擔帪 >= @斕攧擔fr AND
	斕攧擔帪 <= @斕攧擔to AND 
	(@彜昳ID IS NULL OR 彜昳ID LIKE '%' + @彜昳ID + '%') AND
	(@彜昳柤 IS NULL OR 彜昳柤 LIKE '%' + @彜昳柤 + '%') AND
	(@彜昳扨壙 IS NULL OR 彜昳扨壙 = @彜昳扨壙) AND
	(@屭媞ID IS NULL OR 屭媞ID LIKE '%' + @屭媞ID + '%')
ORDER BY
	斕攧擔帪 DESC

---- FillBy屭媞No
--SELECT
--	慻怐No,
--	斕攧棜楌No, 
--	斕攧擔帪, 
--	彜昳ID, 
--	彜昳柤, 
--	彜昳扨壙, 
--	斕攧屄悢, 
--	屭媞ID, 
--	彜昳No, 
--	屭媞No
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞No = @屭媞No
SELECT
	斕攧棜楌No,
	斕攧擔帪,
	彜昳ID,
	彜昳柤,
	彜昳扨壙,
	斕攧屄悢,
	屭媞ID,
	彜昳No, 
	屭媞No
FROM
	H01斕攧棜楌
WHERE
	(屭媞No = @屭媞No)


---- FillBy嵟怴彜昳忣曬
--SELECT
--	TOP (1) 彜昳柤, 
--	彜昳扨壙
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	彜昳No = @彜昳No
--ORDER BY
--	斕攧擔帪 DESC
SELECT
	TOP (1) 彜昳柤,
	彜昳扨壙
FROM
	H01斕攧棜楌
WHERE
	(彜昳No = @彜昳No)
ORDER BY
	斕攧擔帪 DESC


---- FillBy嵟戝椵寁峸擖嬥妟挻_屭媞
--SELECT
--	屭媞ID
--FROM (
--		SELECT
--			SUM(斕攧嬥妟) AS 斕攧嬥妟椵寁, 
--			屭媞ID
--		FROM
--			H01斕攧棜楌
--		WHERE
--			慻怐No = @慻怐No
--		GROUP BY
--			屭媞ID
--	) AS tb
--WHERE
--	(斕攧嬥妟椵寁 > @嵟戝斕攧嬥妟椵寁)
SELECT
	屭媞ID
FROM
(
	SELECT
		SUM(斕攧嬥妟) AS 斕攧嬥妟椵寁,
		屭媞ID
	FROM
		H01斕攧棜楌
	GROUP BY
		屭媞ID
) AS tb
WHERE
	(斕攧嬥妟椵寁 > @嵟戝斕攧嬥妟椵寁)


---- InsertCommand
--INSERT INTO H01斕攧棜楌 (
--	慻怐No,
--	斕攧擔帪, 
--	彜昳ID, 
--	彜昳柤, 
--	彜昳扨壙, 
--	斕攧屄悢, 
--	斕攧嬥妟, 
--	屭媞ID, 
--	彜昳No, 
--	屭媞No, 
--	搊榐儐乕僓乕No, 
--	搊榐擔帪, 
--	峏怴儐乕僓乕No, 
--	峏怴擔帪
--) VALUES (
--	@慻怐No,
--	@斕攧擔帪,
--	@彜昳ID,
--	@彜昳柤,
--	@彜昳扨壙,
--	@斕攧屄悢,
--	@斕攧嬥妟,
--	@屭媞ID,
--	@彜昳No,
--	@屭媞No,
--	@搊榐儐乕僓乕No,
--	GETDATE(),
--	@搊榐儐乕僓乕No, 
--	GETDATE()
--)
INSERT INTO H01斕攧棜楌 (
	斕攧擔帪,
	彜昳ID,
	彜昳柤,
	彜昳扨壙,
	斕攧屄悢,
	斕攧嬥妟,
	屭媞ID,
	彜昳No, 
	屭媞No,
	搊榐僗僞僢僼No,
	搊榐擔帪,
	峏怴僗僞僢僼No,
	峏怴擔帪
) VALUES (
	@斕攧擔帪,
	@彜昳ID,
	@彜昳柤,
	@彜昳扨壙,
	@斕攧屄悢,
	@斕攧嬥妟,
	@屭媞ID,
	@彜昳No,
	@屭媞No,
	@搊榐僗僞僢僼No,
	GETDATE(),
	@搊榐僗僞僢僼No,
	GETDATE()
)

---- Scalar摨堦審悢_彜昳ID
--SELECT
--	COUNT(彜昳ID) AS Expr1
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	彜昳ID = @彜昳ID
---- FillBy摨堦審悢_彜昳ID
SELECT
	COUNT(彜昳ID) AS Expr1
FROM
	H01斕攧棜楌
WHERE
	(彜昳ID = @彜昳ID)


---- Scalar峸攦夞悢
--SELECT
--	COUNT(屭媞No) AS cnt
--FROM (
--		SELECT 
--			DISTINCT 斕攧擔帪, 
--			屭媞No
--		FROM
--			H01斕攧棜楌
--		WHERE
--			慻怐No = @慻怐No AND
--			屭媞No = @屭媞No
--	) AS tb
SELECT
	COUNT(屭媞No) AS cnt
FROM
(
	SELECT
		DISTINCT 斕攧擔帪,
		屭媞No
	FROM
		H01斕攧棜楌
	WHERE
		屭媞No = @屭媞No
) AS tb


---- Scalar峸攦夞悢_FM
--SELECT
--	COUNT(屭媞No) AS cnt
--FROM (
--		SELECT 
--			DISTINCT 斕攧擔帪, 
--			屭媞No
--		FROM
--			H01斕攧棜楌
--		WHERE
--			慻怐No = @慻怐No AND
--			屭媞No = @屭媞No AND
--			斕攧擔帪 >= @寁嶼懳徾奐巒擔帪 AND 
--			斕攧擔帪 <= @寁嶼懳徾廔椆擔帪 AND
--			斕攧擔帪 <= @懳徾寧
--	) AS tb
SELECT
	COUNT(屭媞No) AS cnt
FROM (
		SELECT
			DISTINCT 斕攧擔帪,
			屭媞No
		FROM
			H01斕攧棜楌
		WHERE
			屭媞No = @屭媞No AND
			斕攧擔帪 >= @寁嶼懳徾奐巒擔帪 AND
			斕攧擔帪 <= @寁嶼懳徾廔椆擔帪 AND 
			斕攧擔帪 <= @懳徾寧
	) AS tb


---- Scalar峸攦嬥妟SUM
--SELECT
--	SUM(斕攧嬥妟) AS 斕攧嬥妟SUM
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞No = @屭媞No
SELECT
	SUM(斕攧嬥妟) AS 斕攧嬥妟SUM
FROM
	H01斕攧棜楌
WHERE
	屭媞No = @屭媞No


---- Scalar峸攦嬥妟SUM_FM
--SELECT
--	SUM(斕攧嬥妟) AS 斕攧嬥妟SUM
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞No = @屭媞No AND
--	斕攧擔帪 >= @寁嶼懳徾奐巒擔帪 AND
--	斕攧擔帪 <= @寁嶼懳徾廔椆擔帪 AND
--	斕攧擔帪 <= @懳徾寧
SELECT
	SUM(斕攧嬥妟) AS 斕攧嬥妟SUM
FROM
	H01斕攧棜楌
WHERE
	屭媞No = @屭媞No AND
	斕攧擔帪 >= @寁嶼懳徾奐巒擔帪 AND 
	斕攧擔帪 <= @寁嶼懳徾廔椆擔帪 AND
	斕攧擔帪 <= @懳徾寧


---- Scalar嵟怴峸攦擔
--SELECT
--	MAX(斕攧擔帪) AS 擔晅
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞No = @屭媞No
SELECT
	MAX(斕攧擔帪) AS 擔晅
FROM
	H01斕攧棜楌
WHERE
	屭媞No = @屭媞No


---- Scalar憤攧忋_婜娫巜掕
--SELECT
--	SUM(斕攧嬥妟) AS 憤攧忋
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧擔帪 >= @斕攧擔帪fr AND 
--	斕攧擔帪 <= @斕攧擔帪to
SELECT
	SUM(斕攧嬥妟) AS 憤攧忋
FROM
	H01斕攧棜楌
WHERE
	斕攧擔帪 >= @斕攧擔帪From AND 
	斕攧擔帪 <= @斕攧擔帪To


---- Scalar摨堦彜昳偱嵟怴
--SELECT
--	COUNT(斕攧棜楌No) AS Cnt
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧擔帪 >= @斕攧擔帪 AND
--	彜昳No = @彜昳No
SELECT
	COUNT(斕攧棜楌No) AS Cnt
FROM
	H01斕攧棜楌
WHERE
	斕攧擔帪 >= @斕攧擔帪 AND
	彜昳No = @彜昳No


---- Scalar斕攧棜楌Cnt
--SELECT
--	COUNT(*) AS Expr1
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No
SELECT
	COUNT(*) AS Expr1
FROM
	H01斕攧棜楌


---- Scalar斕攧棜楌Cnt_婜娫巜掕
--SELECT
--	COUNT(*) AS cnt
--FROM
--	H01斕攧棜楌
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧擔帪 >= @斕攧擔帪fr AND
--	斕攧擔帪 <= @斕攧擔帪to
SELECT
	COUNT(*) AS cnt
FROM
	H01斕攧棜楌
WHERE
	斕攧擔帪 >= @斕攧擔帪From AND
	斕攧擔帪 <= @斕攧擔帪To


---- Update
--UPDATE
--	H01斕攧棜楌
--SET
--	斕攧擔帪 = @斕攧擔帪, 
--	彜昳ID = @彜昳ID, 
--	彜昳柤 = @彜昳柤, 
--	彜昳扨壙 = @彜昳扨壙, 
--	斕攧屄悢 = @斕攧屄悢, 
--	斕攧嬥妟 = @斕攧嬥妟, 
--	屭媞ID = @屭媞ID, 
--	彜昳No = @彜昳No, 
--	屭媞No = @屭媞No, 
--	峏怴儐乕僓乕No = @峏怴儐乕僓乕No, 
--	峏怴擔帪 = GETDATE()
--WHERE
--	慻怐No = @慻怐No AND
--	斕攧棜楌No = @斕攧棜楌No
UPDATE
	H01斕攧棜楌
SET
	斕攧擔帪 = @斕攧擔帪,
	彜昳ID = @彜昳ID,
	彜昳柤 = @彜昳柤, 
	彜昳扨壙 = @彜昳扨壙,
	斕攧屄悢 = @斕攧屄悢,
	斕攧嬥妟 = @斕攧嬥妟, 
	屭媞ID = @屭媞ID,
	彜昳No = @彜昳No,
	屭媞No = @屭媞No, 
	峏怴僗僞僢僼No = @峏怴僗僞僢僼No,
	峏怴擔帪 = GETDATE()
WHERE
	斕攧棜楌No = @斕攧棜楌No


---- Update儕僾儗乕僗屭媞No
--UPDATE
--	H01斕攧棜楌
--SET
--	H01斕攧棜楌.屭媞No = M03屭媞.屭媞No
--FROM
--	M03屭媞
--WHERE
--	慻怐No = @慻怐No AND
--	H01斕攧棜楌.屭媞ID = M03屭媞.屭媞ID
UPDATE
	H01斕攧棜楌
SET
	H01斕攧棜楌.屭媞No = M03屭媞.屭媞No
FROM
	M03屭媞
where
	H01斕攧棜楌.屭媞ID = M03屭媞.屭媞ID


---- Update儕僾儗乕僗彜昳No
UPDATE
	H01斕攧棜楌
SET
	H01斕攧棜楌.彜昳No = M02彜昳.彜昳No
FROM
	M02彜昳
where
	H01斕攧棜楌.彜昳ID = M02彜昳.彜昳ID


---- Update屭媞No
--UPDATE
--	H01斕攧棜楌
--SET
--	屭媞No = @屭媞No
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞ID = @屭媞ID
UPDATE
	H01斕攧棜楌
SET
	屭媞No = @屭媞No
WHERE
	屭媞ID = @屭媞ID


---- Update枹搊榐屭媞偺屭媞No傪0偵偡傞
--UPDATE
--	H01斕攧棜楌 
--SET
--	屭媞No = 0
--WHERE
--	慻怐No = @慻怐No AND
--	屭媞ID NOT IN (
--		SELECT
--			屭媞ID
--		FROM
--			M03屭媞
--		WHERE
--			慻怐No = @慻怐No
--	)
UPDATE
	H01斕攧棜楌 
SET
	屭媞No = 0
where
	屭媞ID NOT IN (
		SELECT
			屭媞ID
		FROM
			M03屭媞
	)

