I’m writing a stored procedure where I’m declaring a temporary table. I need to query multiple rows from the database into that table from a query that I’ve already written. Then I’m doing another query of that temp table. The reason why is lengthy to explain but it’s basically a work-around. Anyways…
The actual query is too lengthy to put here but it’s basically like this.
DECLARE @a TABLE
(
Museum VARCHAR(32),
MuseumID INT,
Country VARCHAR(32),
City VARCHAR(32),
Paintings VARCHAR(32),
Sculptures VARCHAR(32)
);
Now I need to insert rows into this temp table:
I tried this but I don’t think it will work
INSERT INTO @a VALUES
(
SELECT DISTINCT
TOP (100) PERCENT dbo.Museum.Museum,
dbo.Musuem.MuseumID,
dbo.World. Country,
BLAH BLAH BLAH FROM AND WHERE JUNK
)
How can I insert the queried rows from my query into @a?
Please help thanks.
I also tried BULK INSERT but I don’t think I’m doing the syntax right. If anyone could help that would be awesome.
You can do this with
INSERT ... SELECT:TOP 100 PERCENTis absolutely meaningless. Why is it there?