2

How can I define a table type in SQL server when one of the columns is an array of decimals? I'm trying to pass to stored procedure an .NET object one of the fields of which is an array of decimals.

Thanks

6
  • 4
    The normal way is to simply use a separate table. If you really want, you can use XML. Commented May 10, 2015 at 14:00
  • or the worst possible solution: comma-delimited values. Commented May 10, 2015 at 14:01
  • @Gordon Linoff I've added some explanation to my question. Thank you Commented May 10, 2015 at 14:08
  • 2
    ... Or serialize it and store as xml :-) Commented May 10, 2015 at 14:10
  • 1
    Check out Erland Sommarskog's page on Arrays in SQL Server. I feel like I post this link all the time, but it is really useful. He provides some great examples in his section on XML too. Commented May 10, 2015 at 14:12

1 Answer 1

3

t-sql does not support arrays.
You do, however, have some options: here are 3 of them, from the best to the worst:

  1. Create 2 table types, have a column in one act as a foreign key to the other.
  2. Create a table type with a varchar(max) column that will hold your decimal values as a comma delimited string.
  3. Create a table type with an xml data type column.
Sign up to request clarification or add additional context in comments.

2 Comments

I generally agree, but second is worst (from data handling, performance as size points of view) than third.
@MatteoSp in this case, you are correct, and I've edited my answer according to your comment. in other cases xml data type might be a more appropriate solution, even when considering it's size overhead.

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.