Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:54:10+00:00 2026-06-17T07:54:10+00:00

I need to insert the values of these selects into a table. They return

  • 0

I need to insert the values of these selects into a table.
They return many rows and for each row I need to insert a column into a new table.

Ex:

select (select id from X where name=Contacts.Company) as IDClient, 
FirstName + right(' '+ cast(LastName as varchar(20)), 20) as NewName, 
(select id from Y where newid=8 and description=Contacts.JobTitle) as IDRole, 
Initials
from Contacts

And I need to do something like this for each row of this select:

insert into TableX (IDClient,NewName,IDRole,'0','0','0',Initials,'XXX',GETDATE(),NULL,NULL)

Ty

EDITED

insert into TableX (IDClient,NewName,IDRole,'0','0','0',Initials,'XXX',GETDATE(),NULL,NULL)
select 
(select id from X where nAme=Contacts.Company) as IDClient, 
FirstName + right(' '+ cast(LastName as varchar(20)), 20) as NewName, 
(select id from Y where newid=8 and description=Contacts.JobTitle) as IDRole,
Initials
from Contacts

When i execute this I’m getting this error:

“Incorrect syntax near ‘0’.”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:54:11+00:00Added an answer on June 17, 2026 at 7:54 am

    Unless I am missing something you should be able to do this:

    insert into Table (IDclient,NewName,IDRole,Initials)
    select (select id from X where name=Contacts.Company) as IDClient, 
      FirstName + right(' '+ cast(LastName as varchar(20)), 20) as NewName, 
      (select id from Y where newid=8 and description=Contacts.JobTitle) as IDRole, 
      Initials
    from Contacts
    

    You will just use the INSERT INTO...SELECT...FROM.. syntax.

    Now if you do not have a table, then you can SELECT..INTO a new temp table:

    select (select id from X where name=Contacts.Company) as IDClient, 
      FirstName + right(' '+ cast(LastName as varchar(20)), 20) as NewName, 
      (select id from Y where newid=8 and description=Contacts.JobTitle) as IDRole, 
      Initials
    into #table
    from Contacts
    

    Or if you want to use joins for this then:

    insert into Table (IDclient,NewName,IDRole,Initials)
    select x.id as IDClient, 
      c.FirstName + right(' '+ cast(c.LastName as varchar(20)), 20) as NewName, 
      y.id as IDRole, 
      c.Initials
    from Contacts c
    inner join x
      on x.name=c.Company
    inner join y
      on y.description=c.JobTitle
      and y.newid=8
    

    Now your original post shows an insert of this:

     insert into Table (IDclient,NewName,'',IDRole,Initials,NULL)
    

    You have two fields that do not have names with them, this is not correct syntax. In your insert statement to either have to names no columns and insert into all or name the columns that you want to insert values into. You cannot use an empty string '' or null as column names. If you want these values to be inserted then you have to provide the names for them:

    insert into Table (IDclient,NewName,col3,IDRole,Initials,col5)
    select x.id as IDClient, 
      c.FirstName + right(' '+ cast(c.LastName as varchar(20)), 20) as NewName, 
      '' as col3
      y.id as IDRole, 
      c.Initials,
      null as col5
    from Contacts c
    inner join x
      on x.name=c.Company
    inner join y
      on y.description=c.JobTitle
      and y.newid=8
    

    Based on your edit, you need to use the following:

    -- this insert line should state column names not '0', '0', etc
    -- replace these with the names of your columns you are inserting into like the others,
    -- then place these values that you want to insert in the select list
    insert into TableX (IDClient,NewName,IDRole,'0','0','0',Initials,'XXX',GETDATE(),NULL,NULL)
    select 
      (select id from X where nAme=Contacts.Company) as IDClient, 
      FirstName + right(' '+ cast(LastName as varchar(20)), 20) as NewName, 
      (select id from Y where newid=8 and description=Contacts.JobTitle) as IDRole,
      '0',
      '0',
      '0',
      Initials,
      'XXX',
      getdate(),
      null,
      null
    from Contacts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to insert a polygon into a postgresql table polygontable and then return
I need to insert values in to the db. INSERT INTO tblname(f1,f2,f3) SELECT f1,f2,f3
Please I need your help with my script. I'm trying to insert values into
I have comma-separated values. I need a query to insert into SQL Server 2008
I have a table containing a large number of rows. Each row has 2
I have different values in different classes. I need to insert them in the
Hi need insert data in table if the record is not already exits Ex:
Need to insert selected text on the page into textarea. There must be some
I need to insert a huge amount of data into different tables within my
Considering these tables: CREATE TABLE Status (current_partition INT) -- has a single row CREATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.