Avatar of gvamsimba
gvamsimbaFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

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'
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
gvamsimba
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>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.
Avatar of Vikas Garg
Vikas Garg
Flag of India image

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 ......
Avatar of gvamsimba
gvamsimba
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

good
Microsoft SQL Server 2008
Microsoft SQL Server 2008

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.

50K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo