LazyLady LazyLady - 1 year ago 56
SQL Question

Using SQL cursor for displaying data from database

I am making C# Windows Form Application, and it is connected to database.

Theme is: Bookshop.

In one of application's forms, there is DataGridView, which displays information about every book in shop.

In database, one book is unique, with its ISBN, and different books, in that context, can have same name.

Also, books can have many authors.

Meaning, when I make query that displays all books, it lists same book more than one time, to display all authors from that book.

What I want is, of course, to list all authors in one column, in one line, for one book.

I have been told that this could be done with cursors.

But, I can't imagine how to use them.

I don't want exact code, I just need some guidelines to solve this problem.

Also, is there maybe a better way to do this, then to use cursors?

Answer Source

Is the way to get a column into a comma separated list normally:

How to get column values in one comma separated value

Obviously it doesn't have to be a comma separating them, you could put CHAR(13) or whatever you need.