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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 common numbers

Author  Topic 

NoamGr
Starting Member

12 Posts

Posted - 2014-04-30 : 02:48:16
I am looking for the correct query, which give me the number of the correct guess numbers, within the LOTTO ticket.
here it is:

declare @TheWinnerNumbers varchar(40) = '01,02,03,04,05,06,07'
declare @TheTicketNumbers varchar(40) = '01,02,03,04,08,09,10'
the answer should be: 4

declare @TheWinnerNumbers varchar(40) = '01,02,03,04,05,06,06'
declare @TheTicketNumbers varchar(40) = '01,02,03,04,05,06,06'
the answer should be: 7

declare @TheWinnerNumbers varchar(40) = '01,02,03,04,05,06,10'
declare @TheTicketNumbers varchar(40) = '01,02,03,04,05,05,05'
the answer should be: 5
ect'

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-04-30 : 04:14:35
using CSVTable http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable

select count(*)
from CSVTable(@TheWinnerNumbers) w
inner join CSVTable(@TheTicketNumbers) t on w.numberval = t.numberval



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -