Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2007, 12:13 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL 2005

i am trying to insert the values of agencytype column in agent table into agencytype column in financialdata_one table

use agentinformationsql
insert into financialdata_one (agencytype) select agencytype from agent

i am trying to run this query and i get a error msg Msg 515, Level 16, State 2, Line 2
Cannot insert the value NULL into column 'FinancialID_One', table 'agentinformationSQL.dbo.FinancialData_One'; column does not allow nulls. INSERT fails.



could anyone please help me out with this query thanx in advance

 
Old April 6th, 2007, 04:34 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use agentinformationsql
insert into financialdata_one (agencytype) select agencytype from agent
where agencytype is not null


 
Old April 6th, 2007, 11:19 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanq u for ur response but its givin the same error msg

 
Old April 6th, 2007, 02:19 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please post FULL insert query. If the query is only the one above, it should work.
Also try this, if you have changed the default ANSI NULL settings.

use agentinformationsql
insert into financialdata_one (agencytype) select agencytype from agent
where agencytype is not null and agencytype <> NULL


 
Old April 6th, 2007, 08:55 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not passing a value for the FinancialID_One column is the issue. Without knowing the datatype of the FinancialID_One column, I am not sure what value to pass in the example.

Possible example...
insert into financialdata_one (agencytype, financialid_one)
select agencytype, <finanialid_one value>
from agent
where agencytype is not null

In the future, post the schema of the table. It will help understand the insert requirements.

HTH

Adam Gossage
Lake Wylie, SC, USA
 
Old April 9th, 2007, 02:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, adam is right... Praveen should have posted the schema definition along with the error to help understand.

When you are trying to insert values into a table with values to specific columns and not the for the all the columns of the table schema, you should make sure that the columns in the target table that are left out from the INSERT statement should ALLOW NULL, else such columns should also be included in the INSERT statement, unless it is an IDENTITY column. This is how you should be managing inserts into tables, that doesn't include values for the entire row.

Cheers.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
reg conn to sql server 2005 from vb.net 2005.. veda SQL Server 2005 2 July 1st, 2008 12:16 AM
Opening SQL 2000 Jobs in SQL 2005 carumuga SQL Server 2005 0 June 16th, 2008 05:00 AM
Upgrade 2000 DBs to 2005 or install SQL 2000/2005 cJeffreywang SQL Server ASP 0 February 13th, 2008 10:44 PM
Converting from MS SQL 2005 to Sql Epress edition saif44 SQL Language 0 February 16th, 2007 04:17 PM
Sql 2000 VS Sql 2005 Reporting Service abdul_owiusa Reporting Services 0 June 25th, 2006 12:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.