DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Anthony Boudouvas Guest

    Select from a table_var. How ??

    Hi to all,

    can someone tell me how i can do this work?

    declare @cTableName varchar(30)

    set @cTableName = 'clients'
    select * from @cTableName


    this gives me an : Line 4: Incorrect syntax near '@cTableName'.


    The reason i want to this is that i want to pass the tablename (created
    somewhere else)
    in a stored procedure and do some work there.
    I know that i can constract a string and use exec to execute it but for
    several reasons
    this is not an option for me on this.

    Thanks a lot,

    have a great weekend!

    anthonyb



  2. #2
    DaveSatz Guest

    Re: Select from a table_var. How ??

    checkout: http://www.mssqlserver.com/faq/devel...dynamicsql.asp

    You will need to explain: "I know that i can constract a string and use exec
    to execute it but for several reasons this is not an option for me on this"

    --
    HTH,
    David Satz
    Principal Software Engineer
    Hyperion Solutions
    ->Using SQL Server 7.0 SP3/6.5 SP5a/Cold Fusion 4.5.1 SP2/VSS
    (Please reply to group only - emails answered rarely)
    -----------------------------------------------------------------

    "Anthony Boudouvas" <mediatel@ath.forthnet.gr (anthonyb)> wrote in message
    news:3aa8f492@news.devx.com...
    > Hi to all,
    >
    > can someone tell me how i can do this work?
    >
    > declare @cTableName varchar(30)
    >
    > set @cTableName = 'clients'
    > select * from @cTableName
    >
    >
    > this gives me an : Line 4: Incorrect syntax near '@cTableName'.
    >
    >
    > The reason i want to this is that i want to pass the tablename (created
    > somewhere else)
    > in a stored procedure and do some work there.
    > I know that i can constract a string and use exec to execute it but for
    > several reasons
    > this is not an option for me on this.
    >
    > Thanks a lot,
    >
    > have a great weekend!
    >
    > anthonyb
    >
    >




  3. #3
    Anthony Boudouvas Guest

    Re: Select from a table_var. How ??

    > You will need to explain: "I know that i can constract a string and use
    exec
    > to execute it but for several reasons this is not an option for me on

    this"

    I will ask it in another way: Can u help me with that question by providing
    another solution than "execute" ??

    It's just that!

    anthonyb



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links