Dear people from stackoverflow
I'm currently working on a mechanism to export data out of a database. Every record has roughly 30 attributes and I only want to export those attributes which do have an actual value.
If the explanation is not precise enough, here's an example:
+----+-----------+------------+---------+--------+
| ID | Name | Profession | Country | Salary |
+----+-----------+------------+---------+--------+
| 1 | John Doe | NULL | USA | 5000 |
+----+-----------+------------+---------+--------+
| 2 | Jane Doe | Painter | NULL | NULL |
+----+-----------+------------+---------+--------+
| 3 | Jonas Doe | Butcher | England | 8000 |
+----+-----------+------------+---------+--------+
Expected outputs:
John Doe: John Doe, USA, 5000
Jane Doe: Jane Doe, Painter
Jonas Doe: Jonas Doe, Butcher, England, 8000
These outputs should be generated in an XML file.
This should be possible with every record in the database if possible. I was looking for a function that would check if an attribute has a value and depending on that, adds it to the export file or not. Sadly I couldn't find anything like that.
Edit: What i did until now is just writing the query to get all the possible attributes:
CREATE PROCEDURE export @id int AS
BEGIN
SELECT Name,Profession,Country,Salary FROM Employee
WHERE ID = @id;
END
GO
FOR XML
.