sql server - Prevent INSERT of NULL values for Stored Procedure -
i'm working on stored procedure supposed update table order_truckdelivery
info table basket_truckdelivery
if second table has data. there 2 columns in each of tables: int
id
, datetime
column called truckdeliverydate
. if basket_truckdelivery
has date stored current basket id, insert date order_truckdelivery
table.
right now, insert
execute regardless if there in basket_truckdelivery
table, , results in null value truckdelverydate
column in order_truckdelivery
column. want prevent happening not entirely sure how. basically, want perform , insert
order_truckdelivery
table if value of truckdeliverydate
in basket_truckdelivery
not empty or null.
this have far...i have not done work stored procedures, not sure i've missed....
alter procedure [dbo].[savetruckintoorder] @basketid int, @orderid int begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on; -- insert statements procedure here declare @truckdeliverydate datetime if(exists(select uidbasket [basket_truckdelivery] [uidbasket] = @basketid)) begin select @truckdeliverydate = [truckdeliverydate] [basket_truckdelivery] [uidbasket] = @basketid end begin insert [order_truckdelivery] ([uidorder], [truckdeliverydate]) values (@orderid, @truckdeliverydate) end end
alter procedure [dbo].[savetruckintoorder] @basketid int ,@orderid int begin set nocount on; declare @truckdeliverydate datetime if ( exists ( select uidbasket [basket_truckdelivery] [uidbasket] = @basketid ) ) begin select @truckdeliverydate = [truckdeliverydate] [basket_truckdelivery] [uidbasket] = @basketid end if ( @truckdeliverydate not null , @truckdeliverydate != '' ) begin insert [order_truckdelivery] ( [uidorder] ,[truckdeliverydate] ) values ( @orderid ,@truckdeliverydate ) end end
Comments
Post a Comment