Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Combinations

Author  Topic 

bobinorlando
Starting Member

1 Post

Posted - 2013-09-06 : 18:55:07
How would I write a query to produce all combinations for a situation such as the following?

Suppose I wanted to write a sentence, "This is [adjective] [noun]." where [adjective] comes from the Adjective table and [noun] come from the Noun table.

Adjective table looks like e.g.

ID Adj
1 good
2 so so
3 bad

Noun table looks like e.g.

ID Noun
1 apple
2 orange
3 banana

And the result set would look like

This is good apple.
This is so so apple.
This is bad apple.
This is good orange.
This is so so orange.
This is bad orange.
This is good banana.
This is so so banana.
This is bad banana.

I would take a stab at this myself and post even something that doesn't work, but I honestly have no idea how to approach it.

Any pointers in the right direction would be appreciated.

Thanks in advance.

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2013-09-06 : 19:49:44
select 'This is '+ Adjective.Adj+' '+Noun.Noun
from
Adjective,Noun

should do it.
Go to Top of Page
   

- Advertisement -