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.
Author |
Topic |
cable_si
Starting Member
20 Posts |
Posted - 2013-03-04 : 05:41:16
|
HiCan anyone help improving a query i haveI have a table with a list of phone numbersTable1Telephone012122345670121223456801212234569012122345440121223451701212234527012122345370121223454701212234557Iam given 5 phone numbers and i need to check if each one exists in Table1At the moment i am doing 5 individual querysset @existsTel1 = 0select @existsTel1 = 1 from Table1 where Telephone=@telephone1I would like to do this in one query, can anybody help at allthanksSimon |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-04 : 05:59:49
|
so is the prefix part always same?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-04 : 11:46:34
|
If (SELECT count(1) FROM Table WHERE TelephoneNumbers in ('number1','number2',...,'number5'))=5 SET @existsTel1 = 1ELSE SET @existsTel1 = 0CheersMIK |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-04 : 23:10:30
|
put those numbers you've in a table and then use a query likeSELECT p.*,CASE WHEN t.number IS NOT NULL THEN 'Exists' ELSE 'Not EXists' ENDFROM PhoneTable pLEFT JOIN YourTable tON p.Telephone LIKE '%' + CAST(t.yournumber AS varchar(5))+ '%' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|