0

I am writing update query "Update tbl_List Set ListName = 'Hello' where ListId IN (stringArray()).

I have added 5 string values in stringArray() and how to pass it as input parameter to SQL ? How to execute query with Array values?

3
  • ListId is string? Commented May 31, 2017 at 11:29
  • Yes, it's String Commented May 31, 2017 at 12:21
  • See table valued parameters. Commented May 31, 2017 at 13:06

1 Answer 1

1

You can create your query as :

Update tbl_List Set ListName = 'Hello' where ListId IN ('value1' , 'value2' ,'valueN');

Or using a table :

Declare @Val Table (IDs Nvarchar(50) );

Insert into @val values ('value1'),('value2'),('valueN');

Update tbl_List Set ListName = 'Hello' where ListId IN (Select IDs From @Val);

You can loop in your StringArray to pass values , and you can use only one parametre and excute your query as much as the length of your Array.

Also you can use temp tables for that job.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.