Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Query

$
0
0

 

ID

NAME

1

Deepak Kumar

2

Sourabh Shrivastav

2

Amit Wadhwa

3

Ashutosh Tripathi

3

Ashutosh Kumar

3

Rizvi

 

“NameList” table has name of persons with ID.Select query is required for following condition:

If the Id’s are exactly two in number (e.g. count of ID = 2 is exactly two) then the names should be concatenated with 'OR'. When Ids are more than two (e.g. Id # 3 has a count of 3) , the values should be concatenated with 'AND'

Expected Result

 

ID

Name

1

Deepak Kumar

2

Sourabh Shrivastav OR Amit Wadhwa

3

Ashutosh Tripathi AND Ashutosh Kumar AND Rizvi


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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