Urgent

  • Hi Experts,

    How can i insert data into a table from another table.The new table have different column name and in some columns i have to insert a default value.Please help

    TIA

  • Insert into Table1 (col1, col2, col3, col4)

    select ColB, 45, ColA, getdate() FROM Table2

    If you want the default value as specified in the table to go into the column, don't specify that column in your insert statement

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi Nair,

    I used two temporary tables just to show you the insertion from one temporary table to another table with different column names and default current date value,

    Create Table #Temp1

    (val1 int

    ,val2 int)

    Create Table #Temp2

    (val3 int

    ,val4 int

    ,val5 DAtetime)

    Insert into #Temp1 values(1,1)

    Insert into #Temp1 values(2,2)

    Insert into #Temp1 values(3,3)

    Select * From #Temp1

    Insert into #Temp2(val3,val4,val5)

    Select val1,val2,GetDate() From #Temp1

    select * from #Temp2

    Tariq
    master your setup, master yourself.
    http://mssqlsolutions.blogspot.com

  • What if i have N and Q as values in a column in old table and i want N as 1 and Q as 0 in the new table.What i have to do???

  • Solved the issue using case...:P

  • Was this *urgent* ? :hehe:


    * Noel

  • Hi ,

    How can i insert three column values together in a single column and i need a space of char(13) in between each column value???

    TIA

  • insert into Table1 (ConcatenatedColumn)

    Select Col1 + ' ' + col2 + ' ' + col3 From SomeOtherTable

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply