doku
doku

Reputation: 11

column values into one string in sql stored procedure

I have and address table with the following columns:

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)

Upvotes: 1

Views: 3878

Answers (2)

t-clausen.dk
t-clausen.dk

Reputation: 44316

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

Upvotes: 4

user596075
user596075

Reputation:

Try this:

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

Upvotes: 0

Related Questions