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
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Update using in

Author  Topic 

pssumesh2003
Starting Member

35 Posts

Posted - 2010-01-21 : 05:14:01
Hi every body

i am working using vs2005 and sql server 2005. In my project i want
to execute a query like
update tbltrans set Amount = amount+1000 where id in (100,105,210,225).

i want to pass that Ids through my program . i try like
declare @parameters
update tbltrans set Amount = amount+1000 where id in @parameters

but get a message cannot convert ---


how it possible
please help me?

Kristen
Test

22859 Posts

Posted - 2010-01-21 : 05:18:55
You can't use a parameter for IN(...)

You can use a SPLIT function to convert @parameters into a "table":

update U
set Amount = amount+1000
FROM tbltrans AS U
JOIN dbo.MySplitFunction(@parameters) AS S
on S.SplitID = U.id
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-21 : 05:19:52
Split function discussed here:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

start at the last page (for the most recent / relevant information) and work backwards.
Go to Top of Page

pssumesh2003
Starting Member

35 Posts

Posted - 2010-01-21 : 06:58:13
Thank u
Go to Top of Page
   

- Advertisement -