1

My table consists of multiple phone number columns and I want to select multiple columns (say phone numbers) into an array for my store procedure. I am trying to use SELECT but it returns only one value as shown in the sample code

DECLARE @phone VARCHAR(15)
    SELECT @phone = phone1 FROM AddressTable
PRINT @phone

Now I want get the values of more than one column value into one variable. I know for this purpose we normally use arrays. But I am not sure how to use. Any Help...!!!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
vkrams
  • 7,267
  • 17
  • 79
  • 129
  • 1
    Are you just trying to concatenate multiple columns into a single variable? `SELECT @phone = phone1 + ', ' + phone2 ...` – sgeddes Jun 05 '13 at 01:06
  • 1
    @Vikram . . . What are you actually trying to accomplish? The table format might be quite sufficient to solve your problem. – Gordon Linoff Jun 05 '13 at 01:28
  • I am trying to verify the phone number format for 5 columns. I am using tsqlt. I used table format and I found its helpful. But I need to compare those results with a unique number – vkrams Jun 05 '13 at 01:44
  • @Vikram . . . Why do you need all the numbers at once for verification? Just validate one phone number at a time. – Gordon Linoff Jun 05 '13 at 01:47
  • I need to test with different permutations so testing all the phone numbers columns for each test with unique phone number. which will finish off 8 tests for 5 fields. – vkrams Jun 05 '13 at 01:49
  • @Vikram . . . If you need permutations, then a SQL `select` statement should be fine. How do you get 8 tests for 5 fields? – Gordon Linoff Jun 05 '13 at 02:00

1 Answers1

1

SQL doesn't support arrays. You can use something like a table variable or a comma delimited string

SELECT INTO a table variable in T-SQL

Community
  • 1
  • 1
TGH
  • 38,769
  • 12
  • 102
  • 135
  • You mean append all the phone numbers into a string? – vkrams Jun 05 '13 at 01:07
  • I would go with the table variable, but you could go the delimited string route as well... Or xml or some other "multi" value format – TGH Jun 05 '13 at 01:10