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
 how to update database using an array?

Author  Topic 

haekz008
Starting Member

10 Posts

Posted - 2012-01-19 : 08:42:52
i have a problem on how am i going to update the group number of the students whose ID number is in the array?

heres my code

UPDATE table_student
SET stud_group_number=1
WHERE stud_id= (id number which is insde the array (In here an array should apear))

tnx,.,i just dont have any idea on how these things work.,

haekz008

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-19 : 08:50:21
Maybe this is helpful:
http://www.sommarskog.se/arrays-in-sql-2005.html


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-19 : 09:15:16
so you have a number of different students that you want to update? based on a list of student ID's?

You can use an IN list.

UPDATE table_student SET
[stud_group_number] = 1
WHERE
[stud_id] IN ( 10, 3, 4, 6, 111, 23 )


If you want to pass such an array from a program into your database stored proc or whatever then the link that webfred posted will tell you everything you need to know.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -