Results 1 to 3 of 3

Thread: [RESOLVED] Dynmaic SQL Help.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    308

    Resolved [RESOLVED] Dynmaic SQL Help.

    Hey Guys,

    I've done this a zillion times but beingMonday its way over my poor head ....


    I want to set a variable from an exec of a dynamic SQL but the syntax is wobbly.

    Like below (just for explanation)
    Code:
    DECLARE @C Char(20)
    DECLARE @SQL Char(200)
    
    Set @SQL = 'Select Top 1(Name) from tbl_Addr'
    
    Set @C = Exec(@SQL)
    Done it before but can't remember how...

    Thanks

    Chubby..

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Dynmaic SQL Help.

    You cannot return a value when executing a dynamic t-sql statement, nor can you access the results of the statement unless they are placed in a global temporary table.

    Perhaps you are thinking of the syntax of the Exec command to get the return value from a stored procedure.

    Declare @C int

    Exec @C = usp_SomeStoredProcedure

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    308

    Resolved [resolved] Re: Dynamic SQL Help.

    Quote Originally Posted by brucevde
    You cannot return a value when executing a dynamic t-sql statement, nor can you access the results of the statement unless they are placed in a global temporary table.

    Perhaps you are thinking of the syntax of the Exec command to get the return value from a stored procedure.

    Declare @C int

    Exec @C = usp_SomeStoredProcedure
    ahh Bruce, Thanks for the reply. You can return the results to a variable (or variables), I remembered how I didi it. You use sp_executeSQL...

    Cheers

    Chubby..

Posting Permissions

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



Click Here to Expand Forum to Full Width