how to build tables at run time in sql server 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manivelk
    New Member
    • Jan 2008
    • 21

    #1

    how to build tables at run time in sql server 2005

    Hi,

    Hi to all, I am manivel.. i have two tables in sql server 2005.. now i want to select some items from this two tables and want to save in new table.. please any one help me, how to create tables at run time..

    Thanks inadvance..

    Cheers,
    Manivel. K.
  • Gandhi M K
    New Member
    • Mar 2008
    • 1

    #2
    Originally posted by manivelk
    Hi,

    Hi to all, I am manivel.. i have two tables in sql server 2005.. now i want to select some items from this two tables and want to save in new table.. please any one help me, how to create tables at run time..

    Thanks inadvance..

    Cheers,
    Manivel. K.
    Hi.
    I am not getting u fully..i guess like

    select table1.field1, table2.field into newtablename from table1, table 2 where table1.field= table2.field

    By
    Gandhi M K

    Comment

    • deric
      New Member
      • Dec 2007
      • 92

      #3
      Hi.. You can do something like this

      DECLARE @MyTable AS TABLE (Column1 INT, Column2 VARCHAR(10))
      INSERT INTO @MyTable (Column1, Column2)
      VALUES (
      (SELECT Num1 FROM Table1 WHERE TableID = '1'),
      (SELECT Name FROM Table2 WHERE TableID = '1')
      )

      This, however, won't retain the created table when the query execution ends.

      Comment

      Working...