با اين تفاسير دستور update رو بايد اينطوري بنويسم ؟
CREATE PROCEDURE M_K_Kharid_UPDATE
@cod as int,
@codkala as int,
@codmoshtari as int ,
@noaekharid as nchar(10),
@takhfif as money,
@date1 as datetime
AS
declare @price as money
/*ايا چنين ركوردي وجود دارد ؟ */
if (select count(*) from kharidmoshtari where @cod=cod)>0
begin
/* جهت جلوگيري از ورود مقادير تكراري */
if (select count(*) from kharidmoshtari where (cod=@cod and @codkala=codkala and @codmoshtari=codmoshtari and @noaekharid=noaekharid and @takhfif=takhfif and @date1=date1))=0
begin
update kharidmoshtari set codkala,codmoshtari,noaekharid,takhfif,date1,price 1
select @codkala,@codmoshtari,@noaekharid,@takhfif, @date1, sum(kala.ghamatfo*kharidmoshtari.tedad) as price
where cod=@cod
from kala
join kharidmoshtari
on kala.cod=kharidmoshtari.codkala
group by kharidmoshtari.tedad, kala.ghamatfo, kharidmoshtari.cod
return 1
end
end
else
return 0
GO
كه خطا ميده و موقعي كه اينجوري هم مينويسم بازم خطا ميده ؟
CREATE PROCEDURE M_K_Kharid_UPDATE
@cod as int,
@codkala as int,
@codmoshtari as int ,
@noaekharid as nchar(10),
@takhfif as money,
@date1 as datetime
AS
declare @price as money
/*ايا چنين ركوردي وجود دارد ؟ */
if (select count(*) from kharidmoshtari where @cod=cod)>0
begin
/* جهت جلوگيري از ورود مقادير تكراري */
if (select count(*) from kharidmoshtari where (cod=@cod and @codkala=codkala and @codmoshtari=codmoshtari and @noaekharid=noaekharid and @takhfif=takhfif and @date1=date1))=0
begin
update kharidmoshtari set codkala=@codkala,codmoshtari=@codmoshtari,noaekhar id=@noaekharid,takhfif=@takhfif,date1=@date1,price 1
select @codkala,@codmoshtari,@noaekharid,@takhfif, @date1, sum(kala.ghamatfo*kharidmoshtari.tedad) as price
where cod=@cod
from kala
join kharidmoshtari
on kala.cod=kharidmoshtari.codkala
group by kharidmoshtari.tedad, kala.ghamatfo, kharidmoshtari.cod
return 1
end
end
else
return 0
GO