如果是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)

解决方案 »

  1.   


    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
      

  2.   

    如果是2000,试试这个:
    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
      

  3.   

    谢谢大家。谢谢yupeigu, 可以了。其实我也就是想把表中的pzn值得更新。