1

I have and address table with the following columns:

  • addressId
  • buildingName
  • streetNo
  • streetName
  • streetType
  • subAddressNo
  • subAddressType
  • suburb
  • postCode
  • state

What I want is to SELECT * from address where addressId = @addressId, and that return would be all columns concatenated into one string. Something like:

set @addressString = (SELECT * from address where addressId = @addressId)
0

2 Answers 2

4
select coalesce(cast(addressId as varchar)+ ',', '')  + coalesce(buildingName+ ',', '') 
coalesce(cast(streetNo as varchar)+ ',', '') -- + and so on 
from address

remember to cast the numeric types as varchar

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

Comments

0

Try this:

SELECT buldingName + ' ' + streetNo + ' ' + streetName + ' ' + theRestOfYourColumns AS ClientAddress
FROM YourAddressTable
WHERE addressId = @addressIdPreviouslyAssignedVariable

1 Comment

I know this probably goes without saying, but I just didn't type out all of the column names, but use any configuration you would like.

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.