If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > how to wirte a stored procedure which takes query as parameter

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-29-08, 02:45
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
how to wirte a stored procedure which takes query as parameter

Hi,
Can some one help me to write a Sybase stored procedure, which takes sql query as parameter.The procedure should execute that query.

For this i am wonder is there any function in sybase which takes sql query as query and executes it..
Reply With Quote
  #2 (permalink)  
Old 04-29-08, 05:25
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Code:
declare @s varchar(255)
select @s = "select 25 * 5"
exec (@s)
Just google for dynamic sql. Passing the sql string (or building it in the stored proc) should be the same as passing any string to a stored proc.

Mike
Reply With Quote
  #3 (permalink)  
Old 04-29-08, 08:43
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
thank you..
Reply With Quote
  #4 (permalink)  
Old 04-30-08, 09:50
stuarta stuarta is offline
Registered User
 
Join Date: Mar 2007
Posts: 86
dynamic sql stored proc

USE sybsystemprocs
go
IF OBJECT_ID('dbo.sp_dba_dynaSQL') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.sp_dba_dynaSQL
IF OBJECT_ID('dbo.sp_dba_dynaSQL') IS NOT NULL
PRINT '<<< FAILED DROPPING PROCEDURE dbo.sp_dba_dynaSQL >>>'
ELSE
PRINT '<<< DROPPED PROCEDURE dbo.sp_dba_dynaSQL >>>'
END
go
create proc sp_dba_dynaSQL @sqlstring varchar(1000)
as
exec (@sqlstring)
go
EXEC sp_procxmode 'dbo.sp_dba_dynaSQL','unchained'
go
IF OBJECT_ID('dbo.sp_dba_dynaSQL') IS NOT NULL
PRINT '<<< CREATED PROCEDURE dbo.sp_dba_dynaSQL >>>'
ELSE
PRINT '<<< FAILED CREATING PROCEDURE dbo.sp_dba_dynaSQL >>>'
go
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On