Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

SQL query not finished - no idea how to solve

$
0
0

Hello community,

hopefully this is the right forum to ask such a question:

I have a sql Query that is working fine:

Select GROUP_CONCAT(ID, "---") from table1 where ID2=123

That gives me the output example (example1):

1---,2---,3---,4---,

Sometimes when the "where ID2" is changing, I get another result (example2):

Select GROUP_CONCAT(ID, "---") from table1 where ID2=123456

1---,2---,

Okay the behavior is fine, but I want to achive that the minimum and maximum return value is every time 10 values.

That means whenever I run the query I would like to have the result fullfiled up to 10 or minimized to 10 values in the string. For example when I change the example1 to the output I want to achieve:

1---,2---,3---,4---,0,0,0,0,0,0,

For example2 I would like to achieve:

1---,2---,0,0,0,0,0,0,0,0,

Every row has now 10 values.

It is also important when the return values is already higher than 10 values it should decrease to 10 values. For example:

1---,2---,3---,5---,6---,7---,8---,9---,10---,11---,12---,13---,

--> should decrease to:

1---,2---,3---,5---,6---,7---,8---,9---,10---,

How can I achieve this?

Thank you very much

Paul



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>