SQL Query, For Trigger, Store Procedure, Functionand View
SQL Query, For Trigger, Store Procedure, Functionand View
return
/******Using Cursor**/
ALTER PROCEDURE [dbo].[sp_ins_carry_ammount_paid_carryforward]
@Payout_No as nvarchar(20)
AS
declare @mem nvarchar(20),@lvlcomm numeric(12,2),@fwdstatus
int,@fwdstatus1 int
Triggers:
/**************Insert**/
as
declare @franchid nvarchar(20),@member nvarchar(10),@pincomm
numeric(5),@joincomm numeric(5)
SELECT
@franchid=franchise_id,@member=memberid,@pincomm=franch_pin_comm,@joinco
mm=franch_join_comm FROM INSERTED
IF @franchid <>'NULL'
BEGIN
if exists (select franchise_id from franch_join_comm where
franchise_id=@franchid )
begin
update franch_join_comm set
totalcomm=(totalcomm+@pincomm+@joincomm) where franchise_id=@franchid
end
else
begin
insert into franch_join_comm (franchise_id,totalcomm)
values (@franchid,(@pincomm+@joincomm) )
end
END
Views
Function
/****** To display Date format***/
ALTER function [dbo].[fnFormatDate]
(
@inputDate datetime,
@formatString varchar(25)
)
returns varchar(20) as
begin
declare @returnValue varchar(25)
-- Convert the supplied date to day mon year (25 Jan 2008)
set @formattedDate = convert(varchar, @inputDate, 106)
-- Format the day value based on the format string for the day
select @day =
case @dayFormat
when 'dd' then master.dbo.fn_pcre_replace(@formattedDate,
'^(\d+).*', '$1')
when 'ddd' then substring(datename(dw, @formattedDate), 1, 3)
when 'dddd' then datename(dw, @formattedDate)
else convert(varchar, day(@formattedDate))
end
-- Format the month value based on the format string for the month
select @month =
case @monthFormat
when 'mm' then master.dbo.fn_pcre_replace(convert(varchar,
@inputDate, 101), '^(\d+)/.*', '$1')
when 'mmm' then master.dbo.fn_pcre_replace(@formattedDate,
'\d+\s(\w+)\s\d+', '$1')
when 'mmmm' then datename(m, @formattedDate)
else convert(varchar, month(@formattedDate))
end
-- Format the year value based on the format string for the year
select @year =
case @yearFormat
when 'yy' then substring(convert(varchar, year(@formattedDate)),
3, 2)
else convert(varchar, year(@formattedDate))
end