0

How to Declare array in stored procedure. Adding values to array through query. and iterating through a loop for array elements in mssql stored procedure .

5
  • 1
    There are no arrays on SQL Server, can you clarify what you want?, it sounds like you want to iterate through rows from a table. Commented Feb 7, 2013 at 14:04
  • Yes exactly. I need to iterate through rows from a table. How can i do this in stored procedure without array. Commented Feb 7, 2013 at 14:09
  • 1
    You might also want to give more information about why you want to loop over a table. In SQL Server code you should usually avoid doing that if possible, although there are certainly times when it's necessary. If you can explain more about what your problem is, someone may be able to help you avoid a loop completely. Commented Feb 7, 2013 at 14:20
  • I need to check if perticular entry is present in the table if present then update else insert. I have multiple rows of data and i need to check each row Commented Feb 8, 2013 at 4:05
  • Updating else inserting (also referred to as a merge or sometimes an "upsert") has been asked about dozens of times already. I suggest you review the existing questions and if you're still stuck then explain what you've tried and why it isn't working. Commented Feb 14, 2013 at 21:36

2 Answers 2

1

TSQL does not provide arrays. Use table variables instead.

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

2 Comments

How can i iterate through a column in table
I have multiple rows of data and i need to check each row
0

To quickly answer this set of questions:

1) Rather than arrays you can use Table variables or temporary tables

2) To add values to array through query you can use SELECT INTO or INSERT statement

3) To iterate trough items you can use either CURSOR or WHILE loop

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.