Does anybody know how can I fill in the varchar variable with the content of any row in T-SQL table ?
For example, I have next table:
id name Age city
1 Alice 10 London
When we read the current value of column we need to check if it is NOT NULL we write it to the @description variable.
I need to get the result in a next maner:
@description = "id: 1; name: Alice; Age: 10; city: London";
I will be very glad if someone could tell me how to solve this problem.
Thanks in advance.
Just concatenate the columns (you'll have to convert the numeric columns first):
select 'id: ' + convert(varchar(10), id) + '; name: ' + name + '; Age: ' + convert(varchar(10), age) + '; city: ' + city from test