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
 Where with Update

Author  Topic 

mohdasim87
Starting Member

3 Posts

Posted - 2009-07-10 : 18:47:54
Frnds, i am new to SQL , i am trying to use SQL update command with where as a clause

i want to update 2 specific roll numbers. Currently i am doing this

update dbname
set program = 'MS'
where rno = '001'

This works perfectly , but when i try to update both of them at the same time it dosnet like

update dbname
set program = 'MS'
where rno = '001' and rno = '002'

this command executes perfectly , but shows 0 effected rows.

ANYONE can help me out.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-10 : 19:41:42
[code]update dbname
set program = 'MS'
where rno = '001' and OR rno = '002'[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mohdasim87
Starting Member

3 Posts

Posted - 2009-07-11 : 04:33:28
Friend , when i type your syntax it gives me this error :-

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'OR'.

and when i remove OR from there it give me this :-

(0 row(s) affected)

but when i try to update just 1 roll number , then it gives me this msg

(1 row(s) affected)
Go to Top of Page

mohdasim87
Starting Member

3 Posts

Posted - 2009-07-11 : 04:34:38
Thanks , it worked with OR
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-11 : 04:34:55
That should be

update dbname
set program = 'MS'
where rno = '001' OR rno = '002'

or

update dbname
set program = 'MS'
where rno in ('001' , '002')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-11 : 04:40:15
quote:
Originally posted by mohdasim87

Friend , when i type your syntax it gives me this error :-

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'OR'.

and when i remove OR from there it give me this :-

(0 row(s) affected)

but when i try to update just 1 roll number , then it gives me this msg

(1 row(s) affected)



you must have just COPY AND PASTE. Note that I strike off the and keyword.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-11 : 06:18:17
quote:
Originally posted by khtan

quote:
Originally posted by mohdasim87

Friend , when i type your syntax it gives me this error :-

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'OR'.

and when i remove OR from there it give me this :-

(0 row(s) affected)

but when i try to update just 1 roll number , then it gives me this msg

(1 row(s) affected)



you must have just COPY AND PASTE. Note that I strike off the and keyword.


KH
[spoiler]Time is always against us[/spoiler]




Thats why I dont use strike option in sql

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -