Page 1 of 1

Inserting into SQL SERVER with a where condition

Posted: Thu Oct 07, 2010 2:00 am
by faizpayi
Hi,

I want to insert some values to the database based on a where condition.Could someone help me on this.I am using sqlsrv drivers.

Thanks in advance

Faiz

Re: Inserting into SQL SERVER with a where condition

Posted: Thu Oct 07, 2010 2:30 am
by requinix
You're wrong about something: either it isn't inserting or there is no "condition" to be applied. Even if you say you're right, there is still no such thing as "inserting" with "a where condition".

What are you trying to do?

Re: Inserting into SQL SERVER with a where condition

Posted: Thu Oct 07, 2010 2:55 am
by faizpayi
i want to execute the following code in php


insert in <tablename> (<fieldnames>) Values(<values...> ) where employeeno = 1;

this query is possible in sql server.The query has no error.But I want to know how to do it when i am running a php page.Like i want to insert the details of an employee whose employee no is 1.

Re: Inserting into SQL SERVER with a where condition

Posted: Thu Oct 07, 2010 3:30 am
by requinix
Possible? I'm looking at the T-SQL INSERT syntax and I don't see how.

What you're trying to do is

Code: Select all

insert in <tablename> (employeeno, <fieldnames>) Values(1, <values...> );
Look at the sqlsrv documentation to see how to execute a query.

Re: Inserting into SQL SERVER with a where condition

Posted: Thu Oct 07, 2010 4:51 am
by faizpayi
Oh sorry.I think i have to use update command for it....