SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 alter table and insert the data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

desikankannan
Posting Yak Master

India
152 Posts

Posted - 11/12/2013 :  12:45:17  Show Profile  Send desikankannan a Yahoo! Message  Reply with Quote
I try to alter the table and insert below code i have drop 5 columns and alter again the table. please help me to solve the issue

IF NOT EXISTS ( SELECT * FROM syscolumns WHERE id = OBJECT_ID('DeathData') AND name IN('DonationTitle','SendDonationsTo','DonationAddress','DonationCity','DonationState','DonationZip' ))
BEGIN
ALTER TABLE DeathData
ADD DonationTitle varchar(50) ,SendDonationsTo varchar(50),DonationAddress varchar(30),DonationCity varchar(30),DonationState varchar(30), DonationZip varchar(30)
END
IF EXISTS ( SELECT * FROM syscolumns WHERE id = OBJECT_ID('DeathData') AND name IN('DonationTitle','SendDonationsTo','DonationAddress','DonationCity','DonationState','DonationZip' ))
BEGIN
insert into tbldonations (donationstitle , donationsto,donaddress,doncity,donstate,donzip)
select distinct DonationTitle , SendDonationsTo,DonationAddress,DonationCity,DonationState,DonationZip from DeathData where SendDonationsTo != ''
END
GO

error

Msg 207, Level 16, State 1, Line 9
Invalid column name 'SendDonationsTo'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'DonationTitle'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'SendDonationsTo'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'DonationAddress'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'DonationCity'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'DonationState'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'DonationZip

Desikankannan

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/12/2013 :  13:58:25  Show Profile  Reply with Quote
Hmm..You're adding columns and immediately trying to populate data from it. WHat does that mean? you'll just have some NULL values getting inserted in tbldonations.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

desikankannan
Posting Yak Master

India
152 Posts

Posted - 11/12/2013 :  19:22:11  Show Profile  Send desikankannan a Yahoo! Message  Reply with Quote
yes,

if the run script first time , it works fine, if the run again second
it throws the error, i don't want to show error message



quote:
Originally posted by visakh16

Hmm..You're adding columns and immediately trying to populate data from it. WHat does that mean? you'll just have some NULL values getting inserted in tbldonations.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Desikankannan
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000