Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert Select statement

Author  Topic 

oceanboy
Starting Member

44 Posts

Posted - 2007-06-13 : 03:47:50
Hello~

The task I want to do here is kind of strange but I wonder whether i can do so

I have a table with the following columns:
ID as int , DESCRIPTION as nvarchar, VALUE as nvarchar

Then i will populate the table with the following statement:

insert into id, value
select id, price from table a inner join table b
on a.xx = b.xx

However, I would like to fill in the DESCRIPTION with the word "Average". Is it possible to do so while I INSERT#12288;INTO that table instead of using UPDATE statement?

One thing to bear in mind that this table will not be used only by 1 process but the others. Therefore the VALUE column doesnt not only store price but also other information. That's why the DESCRIPTION column is there.

Thus, the table will look like this
1 Average 5
2 Average 4
3 Average 5
1 Discount 5
3 Discount 1

Thanks in advance!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-13 : 03:55:31
Yes.

INSERT INTO NewTable (ColA, ColB, ColC) SELECT Col1, 'Average', ColGreen FROM OldTable


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

oceanboy
Starting Member

44 Posts

Posted - 2007-06-13 : 04:11:16
coolio! I thought it could work and you have proved me right! Thanks a zillion!
Go to Top of Page
   

- Advertisement -