How to add multiple column’s data into a single column in SQL Server?
I have columns like Loc_BldgStreet, Loc_Area, Loc_City, Loc_State, Loc_Country and I want to add them all into one single column (in view) to show them in gridview (asp.net) as in single column as full address to avoid very wide grid.
How to do it? I am using linq for binding grid from the location_view.
Thank you!
The + sign is what you use to concatinate strings in SQL.
If one of the columns happens to be numeric (i.e. int) then use convert or cast
If one of the columns allows null, you’ll need to use IsNull otherwise, the entire string will return null:
To create a view:
You can also create a computed column and place your concatination there. Computed columns can also use functions for things like running totals and such and do not require the extra view.