如果是2005版:;with t
as
(
select *, datediff(day, convert(datetime, pyear+'-'+pmonth+'-'+'15') ,
CONVERT(varchar(11) , getdate(), 120 ))*pvale*0.002 as pzn1
from tepto where Pzt<>'已缴费'
)update t
set pzn = cast(pzn1 as varchar)
as
(
select *, datediff(day, convert(datetime, pyear+'-'+pmonth+'-'+'15') ,
CONVERT(varchar(11) , getdate(), 120 ))*pvale*0.002 as pzn1
from tepto where Pzt<>'已缴费'
)update t
set pzn = cast(pzn1 as varchar)
WITH a1 AS
(
SELECT * ,
DATEDIFF(day, CONVERT(DATETIME, pyear + '-' + pmonth + '-' + '15'),
CONVERT(VARCHAR(11), GETDATE(), 120)) * pvale * 0.002 AS pzn1
FROM tepto
WHERE Pzt <> '已缴费'
)
UPDATE a1 SET pzn=pzn1
update tepto
set pzn = cast(t2.pzn1 as varchar)
from tepto t1
inner join
(
select *, datediff(day, convert(datetime, pyear+'-'+pmonth+'-'+'15') ,
CONVERT(varchar(11) , getdate(), 120 ))*pvale*0.002 as pzn1
from tepto where Pzt<>'已缴费'
)t2
on t1.id = t2.id