August 18, 2008 at 2:01 am
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
August 18, 2008 at 2:14 am
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
August 18, 2008 at 2:18 am
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
August 18, 2008 at 3:17 am
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???
August 18, 2008 at 4:26 am
Solved the issue using case...:P
August 18, 2008 at 7:48 am
Was this *urgent* ? :hehe:
* Noel
August 19, 2008 at 2:05 am
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
August 19, 2008 at 2:23 am
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
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply