Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    11

    Unanswered: Table creation & update

    Hi,

    Can you create a table on one line and then update it on the next i.e. in the same query.

    i.e.

    create table test as select * from original
    update test set test.a = .......

    I know that they both work individually but whne i try to run them in one file i get "sql command not properly ended" - when i put a comma after 'original' i then get "invalid table name".

    Am i just missing something

    Cheers

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Why not?

    Code:
    USE Northwind
    GO
    
    SELECT * INTO myTable99 FROM Orders
    UPDATE myTable99 SET OrderDate = '1/1/2004'
    SELECT * FROM myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Post your code as is......
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Posts
    11
    k here is the 3 line code:

    create table students as select * from shared.sessions
    update students
    set students.examno = (select examno from examnos where students.student = examnos.student)

    but i can't get it to run,

    cheers

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    would you want something like

    Code:
    select *.shared.sessions into student
    from shared.sessions
    go
    update students 
    set students.examno = (select examno from examnos where students.student = examnos.student)
    go
    ??
    Last edited by rokslide; 02-17-04 at 18:44.

  5. #5
    Join Date
    Feb 2004
    Posts
    11
    thanks, it works

Posting Permissions

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