Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004

    Unanswered: Return Result from Dynamic SQL

    Hi there,

    I'm a novitiate sybase developer. Can any expert give me any idea to solve following issue?

    I would like to construct a dynamic sql that can return the result to the caller stored procedure as below:

    stored procedure1:
    select @mycount = 0
    select @mytable = "sysobjects"
    select @mytype = "P"
    select @mysql = "select count(*) from " + @mytable + " where type = '" + @mytype + "'"
    exec (@mysql)

    After run above stored procedure1, how can I put the mysql exec return value to @mycount variable? I just think that I can put the result to #temp table, then the stored procedure1 can read the result in the same session. Is it a proper way to handle the return value?

    Thanks in advance!

  2. #2
    Join Date
    Jun 2004
    Paris, France
    i think the temp table is your only way...

    so you can try :

    create table #count (nbRows int null)

    select @mycount = 0,
    @mytable = "sysobjects",
    @mytype = "P",
    @mysql = "insert #count select count(*) from " + @mytable + " where type = '" + @mytype + "'"

    exec (@mysql)

    select nbRows
    from #count

Posting Permissions

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