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
 General SQL Server Forums
 New to SQL Server Programming
 Fill a db.table with a select query result

Author  Topic 

Giacomo1983
Starting Member

5 Posts

Posted - 2011-12-14 : 10:52:25
Hi All I'm new here.

I wanna fill a db.table with some static data and other data who are result from a select query.. for example:

I have my table TOTAL.RESULT with 3 coloumn: ID,NAME,DATA

than I have another table PERSON with 2 coloumn: ID,NAME

Than I wanna fill TOTAL.RESULT Table with a result of select * from PERSON
UNION
a value from TOTAL.RESULT(DATA) which is given from the user or is taken from the current data (should be a static data!)

Are there some way to do this??

Thank you in advance and sorry for my english.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-14 : 11:13:34
some thing like

INSERT INTO RESULT
SELECT ID,NAME, <the static data> FROM PERSON


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Giacomo1983
Starting Member

5 Posts

Posted - 2011-12-14 : 16:23:10
Thanks a lot for your reply! As soon as possible I'll try your code and I'll post a reply.
Go to Top of Page

Giacomo1983
Starting Member

5 Posts

Posted - 2011-12-15 : 06:10:46
YES!! It is working! thanks a lot man.
I'll came back if something else goes wrong!! (Hoping not :))

Bye
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-15 : 06:27:49
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-12-15 : 06:29:12
just a tiny thing:

It's not good form to do blind inserts like that

INSERT INTO <table>
SELECT <foo>

Because if the table definition changes (say you move some columns around or add more (nullable) collumns then your INSERT statement will break

It's better to do:

INSERT INTO <table> ( <COLUMN LIST> )
SELECT <COLUMN LIST> FROM .....


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -