tsql INSERTS

Hi, I have created a temp table with 2 columns and I want to populate those 2 columns with values from the table named Question but sql does not allow me to do that. Is there any easy way to achieve this ?

Many Thanks

      CREATE TABLE [#Question](
   [QuestionID] int
  ,[NewQuestionID] int)

  INSERT INTO #Question

  SELECT QuestionID from Question Where Reference = 'abc', SELECT QuestionID from Question Where Reference = 'xyz'
gvamsimbaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
try this:

INSERT INTO #Question
select (SELECT QuestionID from Question Where Reference = 'abc'), (SELECT QuestionID from Question Where Reference = 'xyz') 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Data DudeCommented:
>sql does not allow me to do that
Define this, preferably with an error message, as we can't connect to your data source or run queries, so we have no idea what this means.

An alternate solution..
INSERT INTO #Question (QuestionID) 
SELECT QuestionID from Question Where Reference = 'abc'
UNION
SELECT QuestionID from Question Where Reference = 'xyz'

Open in new window

Also this implies that since I don't see column NewQuestionID in the INSERT statement, that NULL values are allowed, and you're okay with NULLs in the two rows being inserted.
Vikas GargAssociate Principal EngineerCommented:
Hi,

If the issue is with access to the tempdb you can try using table variable in place of temp table

Declare @tbl Table(col1 int .....)

insert into @tbl
Select ......
gvamsimbaAuthor Commented:
good
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.