views:

41

answers:

1

Edit

Ok I solved all my problems but one. Is it possible to have a hardcoded value insert as well. Like I said I am trying to insert one row(some of its columns) into another table that has about 80% of the same columns however the remaining ones hard non null columns and need some value to be inserted into them.

I am wondering can I send a hardcoded value or should I just make them nullable?

Hi

I am trying to find rows that are not in one table and insert them into another. The table I am trying to insert into has less columns then the other one.

These columns are null but it would be cool if I could hardcode a value before I do the insert.

But I am having so much trouble with just trying to get it to insert.

I have something like this

SELECT p.ProductId, p.ProductName
INTO SomeTable
FROM Product as p
WHERE p.ProductName != 'iPad'

I will get a error like this though

Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "p.ProductId" could not be bound.

I am not sure what I am doing wrong. I copied and pasted the names in so I don't think it is a spelling mistake.

I am using ms sql 2005 express.

Edit

I forgot to update my where clause with the alias name that why I was getting this error. Now I get a new error

There is already an object named 'SomeTable' in the database.

My where clause.

SELECT p.ProductId, p.ProductName
INTO SomeTable
FROM Product as p
WHERE NOT EXISTS (SELECT * FROM SomeTable WHERE p.ProductId = SomeTable.ProductId)
+2  A: 

The sintaxe should be something like:

INSERT INTO table (f1, f2)
SELECT a, b
FROM table2
WHERE somefield = 'some_value'

I think...

Ronaldo Junior