Select from a table_var. How ??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Select from a table_var. How ??

  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



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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center