Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert into specific row

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-04-11 : 15:37:34
Hi.I'd like to add valuse to a row where has this condition:
WHERE affiliate_id = '#session.AffiliateInfo.userid#'
I did it like this:

INSERT INTO tbl_affiliate
(affiliate_tax_number, affiliate_SSN_number)
VALUES
('#Form.SSNumber#','#Form.TIDNumber#')
WHERE affiliate_id = '#session.AffiliateInfo.userid#'

but it gave me error.how should I write the query?
thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-11 : 15:40:30
You can't do like that:

It should be:

Insert into [yourtable](col1,col2,.....)
select col1....... from table
WHERE affiliate_id = '#session.AffiliateInfo.userid#'

Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-04-11 : 15:43:42
thanks.
I will do that.
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-04-11 : 16:01:39
I did it like this:

INSERT INTO tbl_affiliate
('1', '2')
SELECT affiliate_tax_number, affiliate_SSN_number
FROM tbl_affiliate
WHERE affiliate_id = '6500'

but got the error message:Invalid object name 'tbl_affiliate'.
I think we have miscommunication on my part.
I need to add 2 fields in only 2 columns of a row which the affiliate_id = '6500'
then what is wring with this query?
thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-11 : 16:29:19
Which is it?

UPDATE (existing record), INSERT (new record) or something else?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-04-11 : 16:52:08
thanks.it worked.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-11 : 16:55:36
Great!
What did you change?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -