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
 .NET Inside SQL Server (2005)
 select and insert

Author  Topic 

annas
Starting Member

36 Posts

Posted - 2008-04-08 : 11:39:56
Haii...
What i want to do is to select a data from other table and insert into another table. I using below code, but an error occur "There is an object name Bill in database".



SELECT OrderID, TableID INTO Bill
FROM Orders
WHERE (OrderID =(SELECT MAX(OrderID) FROM Orders))

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-08 : 11:44:33
It means table "Bill" already exists in the database. You should check existence of table before running the query.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 2008-04-08 : 12:05:31
if i want to insert a data into table already exist can it be done
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-08 : 12:09:44
In that case, don't use SELECT..INTO, use INSERT INTO TABLE..SELECT statement.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

annas
Starting Member

36 Posts

Posted - 2008-04-08 : 12:27:45
I using below code, but have error, can u identified it

INSERT INTO Bill(OrderID, TableID)FROM Orders WHERE OrderID =(SELECT MAX(OrderID) FROM Orders)
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-08 : 12:37:32
INSERT INTO Bill(OrderID, TableID)
Select OrderID, TableID FROM Orders WHERE OrderID =(SELECT MAX(OrderID) FROM Orders)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -