Inserting into SQL SERVER with a where condition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
faizpayi
Forum Newbie
Posts: 14
Joined: Tue Oct 05, 2010 1:24 am

Inserting into SQL SERVER with a where condition

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Inserting into SQL SERVER with a where condition

Post 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?
faizpayi
Forum Newbie
Posts: 14
Joined: Tue Oct 05, 2010 1:24 am

Re: Inserting into SQL SERVER with a where condition

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Inserting into SQL SERVER with a where condition

Post 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.
faizpayi
Forum Newbie
Posts: 14
Joined: Tue Oct 05, 2010 1:24 am

Re: Inserting into SQL SERVER with a where condition

Post by faizpayi »

Oh sorry.I think i have to use update command for it....
Post Reply