• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem with multiple select statements

Participant ,
Nov 21, 2007 Nov 21, 2007

Copy link to clipboard

Copied

I have a stored procedure where I am creating a table variable and then doing an insert and the problem I am having is seperating my select statements that I using to insert in the table variable. I have tried wrapping each select statement in parentheses and seperating them with a comma; however, that does not work either. I also tried aliasing the select statement with the same column name. I am going to using the return on this stored procedure for a charting graphic.

Here is a SP and below is the error.


The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
TOPICS
Advanced techniques

Views

317

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Nov 21, 2007 Nov 21, 2007
I would try and rewrite it as a single query using case statements. But the syntax that might work is

insert into @SomeTable (col1, col2, col3)
select (select count(*) from @OtherTable),
(select count(*) from @OtherTable),
(select count(*) from @OtherTable)


> [TWO_RACES] [int] NULL)

And that would be uumm... everybody. LMAO


Votes

Translate

Translate
Valorous Hero ,
Nov 21, 2007 Nov 21, 2007

Copy link to clipboard

Copied

LATEST
I would try and rewrite it as a single query using case statements. But the syntax that might work is

insert into @SomeTable (col1, col2, col3)
select (select count(*) from @OtherTable),
(select count(*) from @OtherTable),
(select count(*) from @OtherTable)


> [TWO_RACES] [int] NULL)

And that would be uumm... everybody. LMAO


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation