R
R
respe-t2015-03-19 16:17:50
Delphi
respe-t, 2015-03-19 16:17:50

How to write an array of integers to a cell in MSSQL Server 2012?

It is necessary for each line to store an array of integers of 10 elements.
At first I did it as a translation into a line with separators, then as 10 fields for each element.
Both options are inconvenient.
Ideally, I want to write down a field as a BLOB in binary (varbinary), but I don't know how.
Environment: Delphi XE2;
DBMS: MS SQL Server 2012

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2015-03-19
@respe-t

You are about to make an architectural mistake. The best is to use 10 columns.

A
Artyom Karetnikov, 2015-03-19
@art_karetnikov

The table is already an array. No need to be smart and write another one to the array.

I
Ilya, 2015-03-19
@geeek

It is best to write in an XML type field, here is the convenience of recording and sampling.
Here is an example in t sql:

DECLARE @i int = 0
DECLARE @table TABLE(num int)
WHILE  @i < 10
BEGIN  
  INSERT INTO @table (num)
  VALUES (@i);
  SET @i = @i + 1
END

SELECT * FROM @table FOR XML RAW('numbers') -- тут нужная вам xml строчка

If you use another language, that is also not a problem. Everyone has the ability to form xml.
In general, you form a line in XML and write it to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question