Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2008
    Posts
    20

    Unanswered: 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..

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  3. #3
    Join Date
    Apr 2008
    Posts
    20
    thank you..

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •