Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    21

    Unanswered: How to pass a table to a procedure

    How do I pass a table to procedure.

  2. #2
    Join Date
    Jan 2004
    Posts
    21
    The answer is

    Create Proc Proc_name
    (@table Varchar(30) = table_name )
    as


    ..

    .
    Select name
    from sysobjects
    where name = @table
    and type = "U"

    .
    .
    .

  3. #3
    Join Date
    Feb 2002
    Location
    Willy is on vacation
    Posts
    1,208

    Re: How to pass a table to a procedure

    Originally posted by dss
    How do I pass a table to procedure.
    If you are after the array variable as in Oracle. I don't think there is any equivalent to it in Sybase. You would have to use a combination of temp tables and cursors to achieve the same effect.

    If you have the latest ASE 12.5.1, you might find the new inline views or derieved tables feature useful for this implementation.

  4. #4
    Join Date
    Jul 2003
    Location
    London
    Posts
    26

    Dynamic SQL

    Hi you can do this using Dynamic SQL with an SP

    CREATE PROCEDURE sp_select @tabname VARCHAR(30)
    AS

    DECLARE @sSQL VARCHAR(255)

    SELECT @sSQL = "SELECT * FROM " + @tabname

    EXECUTE( @sSQL )

    You can combine multiple variables together in the EXECUTE statement if you want, so if your select statement goes over 255 characters then just use another variable as well. I believe the limitation on the 255 character variable length go away on Sybase 12.5.1, not tried so I cannot confirm this.

    The thing to think about is the performance may drop, you wil have to do some testing.

  5. #5
    Join Date
    Jan 2004
    Posts
    51

    Re: How to pass a table to a procedure

    Originally posted by dss
    How do I pass a table to procedure.
    Why do you need to pass the entire table? what is this procedure supposed to do?

Posting Permissions

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