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 3997414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:23:57+00:00 2026-05-20T07:23:57+00:00

I have an INSERT query that works fine, but when I add an extra

  • 0

I have an INSERT query that works fine, but when I add an extra field I get the oh-so-helpful:

Invalid object name ‘optimizations’

Optimizations being the table name. The query is below… I am totally lost as to why this wouldn’t work. If I cut & paste the query into MSSQL Management Studio, the query works fine.

INSERT INTO [optimizations] 
    ([opt_date],[opt_concept_id],[opt_pallet],[opt_turnable],
     [opt_sideupok],[opt_endupok],[opt_flatok],[opt_notstickingout],
     [opt_notinoverhang],[opt_itemsloaded],[opt_loadedweight],
     [opt_pweightutil],[opt_pvolumeutil],[opt_request_xml],
     [opt_response_xml],[opt_images],[opt_primary_stage_id]) 
VALUES 
     (GETDATE(),'775','20ft','true','false','false','true',
      'true','true','10','5952.6','18.6','48.9',
      '<xml><herpa><derpa>xml</derpa></herpa></xml>',
      '<xml><herpa><derpa>xml</derpa></herpa></xml>',
      'img1.jpg,img2.jpg,img3.jpg','98');

For some reason, if I include the last field in the query [opt_primary_stage_id] it does not work… if I omit this field it works fine. Interestingly enough if I add [opt_primary_stage_id] to the list of fields being passed, and pass it a value of NULL the query also works fine. The [opt_primary_stage_id] field’s data type is INT, I have tried including the last entry of the VALUES() section both as a straight number (3) and with quotes ('3')… neither works.

The server executing the code is running PHP 4.3.9, under IIS and with and MSSQL.

This is a version of the query, with the SAME data that will work.

INSERT INTO [optimizations] 
    ([opt_date],[opt_concept_id],[opt_pallet],[opt_turnable],
     [opt_sideupok],[opt_endupok],[opt_flatok],[opt_notstickingout],
     [opt_notinoverhang],[opt_itemsloaded],[opt_loadedweight],
     [opt_pweightutil],[opt_pvolumeutil],[opt_request_xml],
     [opt_response_xml],[opt_images])
VALUES 
     (GETDATE(),'775','20ft','true','false','false','true','true',
      'true','10','5952.6','18.6','48.9',
      '<xml><herpa><derpa>xml</derpa></herpa></xml>',
      '<xml><herpa><derpa>xml</derpa></herpa></xml>',
      'img1.jpg,img2.jpg,img3.jpg');

EDIT: Fixed XML to have proper bracketing & added working query.

  • 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-05-20T07:23:57+00:00Added an answer on May 20, 2026 at 7:23 am

    Adding a field won’t cause failure on it’s own: there is a valid reason.

    You say it runs in SSMS OK then it shows that issue is in PHP or in the call.

    First thoughts:

    • How long is the command. Is it being truncated somewhere in PHP? Is this dynamic SQL IRL?

    • Is the user context the same from the client? You may have the same table in 2 different schemas for example, with differing permissions.

    • Wrong database in the connection. What does SELECT DB_NAME() say? Sounds obvious but no object = not there. Don’t dismiss this idea and assume it is the correct context: check.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
this query works fine using the php_mssql driver: INSERT INTO Table(columnName) VALUES ('text'); SELECT
I have a SQL Insert query inside a stored proc, for inserting rows into
I have a query to insert a row into a table, which has a
Trying to do an insert, I have: jdbcTemplate.update(insert into...., new Object[]{foo.getId(), foo.getName()}) foo.getId() returns
I have a long running insert transaction that inserts data into several related tables.
I have a table that has an insert trigger on it. If I insert
I have a problem with recursive CTE query Let's say that I have that
I have two insert statements, almost exactly the same, which run in two different
I have a huge file, where I have to insert certain characters at a

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.