From: | Rehan Saleem <pk_rehan(at)yahoo(dot)com> |
---|---|
To: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | How to convert SQL store procedure to Postgresql function |
Date: | 2012-02-28 08:50:04 |
Message-ID: | 1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
hi ,
how can i convert this sql store procedure to postgresql function , i shall be very thankful to you, as i am new to postgresql and i dont know how to handle this kind of store procedure in postgresql
thanks
ALTERPROCEDURE [dbo].[sp_GetUserByID]
@UserId varchar(50),
@KBId varchar(50),
@phone varchar(50),
@mhr varchar(50),
@Distance varchar(50)='',
@Total varchar(50) output
AS
BEGIN
DECLARE @sql nvarchar(500);
if (@Distance='')
set @Distance = 1
set @sql = 'select mhr_U, begin_U, End_U, areaSize_U, mhr_KB, begin_KB,
End_KB, areaSize_KB, '
set @sql += ' phone, Distance from vwuserdataSites where UserId=' + @UserId
set @sql += ' and phone>=' + @phone
set @sql += ' AND KBId=' + @KBId
if @mhr<>'All' and ISNULL(@mhr,'')<>''
set @sql += ' AND mhr_U=''' + @mhr +''''
if (@Distance<>'')
set @sql += ' AND (Distance<=' + Distance + ' or ' + Distance + '=1) '
set @sql += ' Order by mhr_U, begin_U'
exec(@sql)
set @Total = @@ROWCOUNT
END
GO
From | Date | Subject | |
---|---|---|---|
Next Message | Filip Rembiałkowski | 2012-02-28 10:36:53 | Re: How to convert SQL store procedure to Postgresql function |
Previous Message | Tom Lane | 2012-02-28 04:15:37 | Re: array_agg order by |