SELECT-INTO query problem

Hi

I have a SELECT-INTO query which I wish to add some additional columns to the destination table. I can create the table and add the columns after it, but I wonder how is it possible to add that columns directly with the SELECT query.

Thanks in advance,

farshad




Answer this question

SELECT-INTO query problem

  • soanfu

    Lots of thanks Geert and Udhaya, but another question: how can I define the new columns's datatype I want them to be Long Integer, my database is Access. And, Udhaya would you please tell me what the "space(30)" mean
    Thanks,
    farshad



  • J. Rizzo

    try this.......

    select space(30) as newcol,name into newtable from oldtable;

  • mxapacbell

    Hi,

    Are you working with SQL Server You can add an additional column like this:

    SELECT *, null AS AdditionalColumn INTO DestinationTable FROM SourceTable

    Don't forget to add an alias to your new column, otherwise it will not work. Although this works, the additional column is not always with the correct datatype.

    When working in SQL Server, it might be easier to create a new table by letting SQL Server generate a script of the source table for you. Then you only need to add your additional column and copy the data.

    Greetz,

    Geert

     

    Geert Verhoeven
    Consultant @ Ausy Belgium

    My Personal Blog



  • Jordi Valldaura Riqué

    Isn't this more a question for the SQL Server T-SQL forum

    http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=85&SiteID=1



  • R.Tutus

    Lots of thanks Geert



  • Penicillin

    Hi,

    - The space function is a function in SQL Server that displays a number of spaces as a string (in this case 30 spaces).

    - There is no real method to define the datatypes in front. For your scenario, you can best set the column as follow:

    SELECT
    *, 0 AS AdditionalColumn INTO Destination FROM Source

    This way, you will receive a column with datatype long integer.

    Greetz,

    Geert

     

     

    Geert Verhoeven
    Consultant @ Ausy Belgium

    My Personal Blog



  • SELECT-INTO query problem