hai,
how to insert a value in a table with where condition in sql server 200.
insert into replies values title='network' where user1="bala"
i use this condition but the error occurs how to solve this
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Krishna GaradPosted Dec 30, 2010, 12:58 AM
Subhendu DePosted Jan 21, 2011, 9:41 PM
I am sure you can use where clause with insert statement... Run the following example in SQL Server 2008 R2
create table maintable(col1 integer,col2 varchar(20))
insert into maintable(col1,col2) values(1,'AAA')
insert into maintable(col1,col2) values(2,'BBB')
insert into maintable(col1,col2) values(3,'CCC')
insert into maintable(col1,col2) values(4,'DDD')
insert into maintable(col1,col2) values(5,'EEE')
insert into maintable(col1,col2) values(6,'FFF')
insert into maintable(col1,col2) values(7,'GGG')
insert into maintable(col1,col2) values(8,'HHH')
create table copytable(col1 integer,col2 varchar(20))
select * from maintable
select * from copytable
insert into copytable
select * from maintable
where col1 between 1 and 5
select * from copytable
Vijay YadavPosted Jan 21, 2011, 12:54 AM
You cannot insert new row with where conditions
Thanks,
Vijay
uday kannaPosted Dec 30, 2010, 3:21 AM
krithika muthukrishnanPosted Dec 30, 2010, 2:53 AM
Sorry i forget that for using update condition thanks,
Subhendu DePosted Dec 30, 2010, 12:56 AM
You can use INSERT with WHERE clause like
insert into replies(col1,col2) values('network','VALUE')
SELECT col1,col2 From UserTable
where user1="bala"