Results 1 to 3 of 3

Thread: Select into

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Select into

    Hi!

    I would like to create a table with a variable table name on the fly.. something like this

    select * into mytable & suser_sname() from etc...

    Any ideas?

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    While I'm sure that there is a more efficient method (I'm too tired to think of it now), you could do the following:
    Code:
    Declare @sql varchar(8000)
    
    Set @sql = "Select * Into myTable" + suser_sname() + " From ..."
    Exec (@sql)
    If you are using SQL Server 2000, you could look into creating functions to create the initial table and to return data from the newly created table.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Tried that..

    Could not get it to work

    set @QueryString="select * into tblAdhChartErrors" + host_name() + " from #tblAdhChartErrors"
    exec (@QueryString)

    ...

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