You are on page 1of 2

use newsoft

--------------------------------------------------------------------------------
-------
CREATE FUNCTION [dbo].get_contactlist
(@acode varchar(30),@opt varchar(1))
RETURNS varchar(500) AS
BEGIN
DECLARE @str varchar(500),@str1 varchar(150)
if @opt='P'
DECLARE tc1 CURSOR LOCAL FOR
SELECT cont_pers+'- '+(case isnull(mobile,'') when '' then isnul
l(phone,'') else isnull(mobile,'') end) as cont
FROM cont_person where acode=@acode ORDER BY cont_pers
else
DECLARE tc1 CURSOR LOCAL FOR
SELECT cont_pers+(case isnull(email,'') when '' then '' else ' (
'+isnull(email,'')+')' end) as cont
FROM cont_person where acode=@acode ORDER BY cont_pers
SET @str=''
OPEN tc1
FETCH NEXT FROM tc1 INTO @str1
while @@fetch_status=0
begin
if len(@str)<>0
SET @str=@str+char(13)
SET @str=@str+@str1
FETCH NEXT FROM tc1 INTO @str1
end
CLOSE tc1
DEALLOCATE tc1
RETURN @str
END
GO
--------------------------------------------------------------------------------
-------
ALTER PROCEDURE mail_cust
@id numeric,@mailopt varchar(10)
AS

select a.[id],b.acode as var_acode,c.[name],


(isnull(c.add1,'')+(case isnull(c.add2,'') when '' then '' else char(13)+c.add2
end)+
(case isnull(c.add3,'') when '' then '' else ', '+c.add3 end)+
(case isnull(c.city,'') when '' then char(13) else char(13)+c.city end)+
(case isnull(c.state,'') when '' then '' else (' '+c.state) end)) as address,c.p
hone
INTO #t
from let_fix a
left outer join let_var b on a.[id]=b.[id]
left outer join custmas c on b.acode=c.acode
where a.[id]=@id
if @mailopt='WITH'
delete from #t where not exists (select top 1 acode from cont_person whe
re acode=#t.var_acode and isnull(email,'')<>'')
else if @mailopt='WITHOUT'
delete from #t where exists (select top 1 acode from cont_person where a
code=#t.var_acode and isnull(email,'')<>'')
select *,dbo.get_contactlist(var_acode,'E') as contact_detail from #t
GO
--------------------------------------------------------------------------------
-------
ALTER PROCEDURE Rep_non_active
@fdate as varchar(10),@tdate as varchar(10),@from_code VARCHAR(50),@to_code as v
archar(50)
AS
declare @tdate1 datetime
declare @date datetime
declare @fdate1 datetime,@TC VARCHAR(5)
set dateformat dmy
set @tdate1=@tdate
Set @Fdate1=@fdate
select acode,[name],ent_date as inv_dt,
(isnull(add1,'')+(case isnull(add2,'') when '' then '' else char(13)+add2 end)+
(case isnull(add3,'') when '' then '' else ', '+add3 end)+
(case isnull(city,'') when '' then char(13) else char(13)+city end)+
(case isnull(state,'') when '' then '' else (' '+state) end)+
(case isnull(phone,'') when '' then '' else (char(13)+'Ph. '+phone) end)) as add
ress into #ts1 from custmas order by acode
UPDATE #ts1 SET inv_dt=''
UPDATE #ts1 SET inv_dt=(select top 1 inv_dt from sblfix where acode=#ts1.acode a
nd demo_fl='S' and
inv_dt BETWEEN @fdate1 and @tdate1 ORDER BY inv_dt desc,inv_no desc)
DELETE FROM #ts1 WHERE inv_dt is not null
UPDATE #ts1 SET inv_dt=(select top 1 inv_dt from sblfix where acode=#ts1.acode a
nd demo_fl='S'
ORDER BY inv_dt desc,inv_no desc)
if len(@from_code)<>0
DELETE FROM #Ts1 WHERE acode<@from_code
if len(@to_code)<>0
DELETE FROM #Ts1 WHERE acode>@to_code
select *,dbo.get_contactlist(acode,'P') as contact_detail
from #ts1
GO
--------------------------------------------------------------------------------
-------
alter table sret_var add excise_rate numeric(18,2)
--------------------------------------------------------------------------------
-------

You might also like