pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rehan Saleem <pk_rehan@yahoo.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: How to convert SQL store procedure  to Postgresql function
Date: Tue, 28 Feb 2012 00:50:04 -0800 (PST)
Message-ID: <1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com> (raw)

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

view thread (5+ messages)  latest in thread

Message-ID: <1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com>
Permalink:  ../1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com/
Also on:    postgresql.org/message-id/1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pk_rehan@yahoo.com
  Subject: Re: How to convert SQL store procedure  to Postgresql function
  In-Reply-To: <1330419004.47440.YahooMailNeo@web121602.mail.ne1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox