Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server selecting a string from table using in clause

I'm having a strange SQL Server issue.

Using the following query:

SELECT id FROM table WHERE id IN ('id1', 'id2', .......)

when id is nchar(30) and 'id1','id2' are values, I get a result which isn't in the values I entered.

Is it possible that SQL Server is searching for a string contained in the values?

Added

query:

SELECT Word FROM WordDictionary WHERE Word IN ('DESPERADO', 'WWW.MYSAVINGS.COM', 'RELIED', 'GALS/GUYS....U', 'MISSOULA', 'STARING...WHY', 'OHIO,,,WHAT', 'ALEYO"MEANS', 'EXCRETE', 'POETERS', 'REMOVAL?IF', 'MOTOT', 'VIEW/SOUND', 'SCHOLD', 'FLINGS', '300000', 'BIGBANG', 'INVOKE', 'COMPLIER', 'UPNISHAD', 'FLUFF/LINT', 'DONATED?..PLEASE', 'EPHEDRINE', 'AGAIN-', 'WHUNT', 'LEVE', 'ARIEL', 'SEIZURES,AND', 'ANYON', 'WELL~AS', 'GGGGGGGGOOOOOOOOOOOOOOOOODDDDD', 'ALGERIA', 'LONDON...CAN', 'TWAIN''S', 'BUTIFUL', 'CIRRHIOSIS', 'PHP-NUKE', 'SCREWD', 'RECONNECT', 'BAND...''SIGUR', 'ROS''', 'DEFLEPOARD', 'FIHGT', 'DRE''S', 'ACQUAINTED', '77067', 'INCREASE/DECREASE', 'AWHILE..SHOULD', 'BABY???..MORE', 'CHRISTEN', 'SUNSLIFE', 'HYANCINTHS', 'NOVEMEBER', 'IEEE', 'IRENE', '5"4', 'BAYSIDE', 'DOJO', 'PEOPLES::DO', 'INFORMATION/ANSWER', 'BLACKWORM', 'MYWIFE.D', '42D', 'COLONEL', 'ESCAPES', 'KW', 'WASH/CLENSE', 'ENCOURAGES', 'HOLINESS', '4710', 'MONOATOMIC', 'FORM-', 'NAVIGATIONS', 'ASHLIEY(TWINS', 'ALIAS....WHAT', 'MARIOKART', 'HORNYNESS', 'CONVERSIONS', 'NUIT', 'PARISTEL:0660442290PL06', 'PUSSY', 'WILLOWS', 'BOYFRIEND/BABYDADDY', 'PARASITES', 'TABOILD', 'J.T', 'TERESEA', '---FREE---', 'KAMORA', 'SIMONS', 'FORSYTHIA', 'RAZORTHOUGHT', 'ABSINTHE', '9-3', 'BAIT-CASTING', 'CUMULATIVE', 'HELP>>>', 'MATZO', 'LIMOSINE', 'SCD353', 'BANGARAM', 'BRUNEL', 'KWTV878', 'NEAPOLITAN', 'OFYOUR', '2SIN', '²', '3SINX', 'IMPERFECTION', 'NONBELIEF', 'FLEM', 'NON-ADJACENT', 'WASHINGTION', 'WHERE/IF', 'BRONTE''S', 'WUTHERING', 'SOMEONE/A', 'TEAM.WHAT', 'PRESIDENT,WHEN', 'DIRICHLET', 'X-AND', 'Y-INTERCEPTS', 'STAMPED', 'PROCRDURE', 'AK32', '*67', 'HANUKKAH', 'MONIE', 'TAGAYTAY', 'NATURES', 'HASS', 'TORMENTS', 'PROPOTIONAL', 'SUDERLAND', 'CONROL', 'CONSEQUENCE', 'SAW?YOU', 'WITHDREW', 'PMT', 'JAIL?WAT', 'DEFFEND', '-12>8X', '4X>6', 'MX-C550', '6-DISC', 'SVQ3', 'BULLSHITING', 'PWEAZE', '23SECONDS', 'VISHWANATHAN''S', 'INTERNALIZING', 'MCCAFFERTY''S', 'TODAY...AND', 'CHANCE....WOULD', 'DEC.''41', '''45', 'HAILLE', 'SELASSIE', 'OF...GREENDAY', 'DEAD/ARMY', 'EX-NFL', 'JACKSONVILLE,FL', 'ATLANTA,HOUSTON,OR', 'ECCENTRICITY', 'CONIC', '[email protected]', '[email protected]', 'DISCRET', '_______', 'ROMACE', 'SUBCATEGORY', 'REDUDUCE', 'EXERCISER', 'MUNITE', 'MESSENGER.SO', 'NIGEL', 'PLANER', 'QUESTION?31576*66496139', 'KODJOE', '919', '1847', 'D.WADE', 'HUMAN''S', 'MULTI-NATIONAL', 'GOGGLE', 'GAAP', 'CONFUSED.IONT', 'ST8', 'ROOM/HOME', 'BOLB', 'GRANDMA-', 'PARSON', 'BELIZE', 'UNITY', 'AWARDS''', 'TOGHTHER', 'LONDON+GREATER', 'JERSEY...IE', 'NETGAR', 'NBC,ABC', 'CONON', 'RECIDENT', 'CANCERS', 'PITTSBURGH/INDY', 'CREATETH', 'MUSICAL''S', 'HEELLLLPPPP', 'MASRER', 'NAME,AND', 'ANAEROBIC', 'SPACIAL', 'SPOUSE/SIGNIFICANT', 'TRIGNOCEPHALY', 'RAW''S', 'BLOGGIN', '9.2', 'FLATTENING', 'FLOWER,ANIMALAND', 'EXPRESSES', 'FRDS', 'NOT?PLS', 'CLEARIFY', 'CLEARFIELD/JEFFERSON', 'HACE', 'FELICIANO', 'MEDICINE--THEY', 'DASCHUND', 'PLINTER', 'SKETCHY', 'I..WHAT', 'JUVENTINA', 'SOMUCH', 'SHEEN', 'HALEX', '11-IN-1', 'URBANIZATION', 'WILWOOD', 'CALIPER', 'NERVE-RACKING', 'OBSESESSION', 'EZRA', 'TALBOT', 'SHOCKWAVE', 'PASCO', '300$-600$', '108,000', '*BOYZ', 'ONLY*PLZ', 'INTERNET)CAN', 'CONCISE', 'TOP40', 'HICUPPS', '4:00', 'OPOSITE', 'NETWORKER?=', 'Q-LINK', 'HSG', 'AMINE', 'RIGHTS,,HOW', 'EMILIANO', 'PEDREGON', 'DILEMA', 'GROUPTHINK', 'MONTEAL', '17...&', '13:04', 'NASHIK', 'NOBIA', 'LINEWIRE', 'ISOCKS', 'DAY........WAIT', 'KATY', 'BODERLINE', 'CONNORS', 'WHWRE', 'CROMWELL', 'COE', '1+1=', 'UMMM.....WHATS', 'BOND''S', 'VIEWLOADER', 'MAXIS', '[email protected]', 'SCISSORS', 'UNSANITARY', 'KANSANS', 'SALINA', '''ARENA''', '''CAROLINA''', 'BIOMAGNIFICATION', 'BIOASSIMILATION', 'WOMBATS', 'POOS', 'ARSES', 'SOCIALIZATION', 'GROUPS,RACES', 'FULL-BLOOD', 'TASMANIAN', 'INCLINE', 'PICA', 'FIGGERED', '9.HE', 'RETINOBLASTOMA,IS', 'COAT''S', '2MOWRO', 'DOTHAN', 'DIFRNT', 'DEPICTS', 'WHAK', 'NETHERLAND', 'FORTHE', 'OFMICROSOFT', 'INDIGO', 'I-MAC', 'SHANGHAINESE', 'DINOSAOUR', 'SUBCAMPS', 'CARDINAL', 'NEBRASKA''S', 'KOMO', 'PIRATE/SAILING', 'ZOPICLONE', 'CRYPTIC', 'CLUE"COULD', 'WHEELCHAIR,NO', 'OVERWIEGHT.DOES', 'ALL..MY', 'BOYFRIIEND', 'MAGTECH', 'TROUBLES...ANY', 'BACK,REDUCED', 'JEWELY', 'CRAFTSMEN''S', 'HAUNTER', 'GENGAR', 'CRYSTAL.WHERE', 'LAHORE', 'SANDLER''S', 'ACCENT...WHAT', 'WOOOOOAAAAAAAAH', 'W''T', '[email protected]', 'SPEICES', 'MCFLY', 'BIOCONVERSION', 'GUERRERO', 'CATHOLICS......WHAT', 'NOV.1--', 'ECONOLINE', 'AMOVIE', 'COUNSELLING', 'HANDSPAN', 'ATTIUTE', 'HAIR??HELP', 'PLASTIC?CERAMIC', 'TITLEIST', 'REISDENTS', '7''S', 'FERMATS', 'JBW&CWW', 'RB''S', 'KENYON', 'BAPTIST''S', 'THUMPERS', 'THOZ', 'HATZ', 'MSNISMS', 'POLL/SURVEY', 'INFUSION', 'FUNDRAISER', 'PROTECTS', 'ANTOINO', 'SYALLBUS', 'GCSES', 'SPIDER,SNAKE,DOG,CAT', 'KNOW.PLEASE', 'CHACH', 'DISSAPIONTED', 'TODGER', 'SH*TTING', 'LODESTONE', 'SARBANES', 'OXLEY', 'ANOTHR', 'RELATIONSHIP????HOW', 'T9', 'JIGGLY', 'GOOD?IS', 'HARDEN', 'DESERT?I', 'SIGNIFANT', 'WEDO', 'SCHAT', 'LQ', 'TENCHI', 'ME...WHAT''S', 'ERUPTED', '£40', '£150', 'UPGRATE', 'I500', '2003SE', 'PROMOT', 'SALUTES', 'GRAEME', 'SOUNESS', 'SERRONE', 'AHAVE', 'BUSTSA', 'IMPARTIAL', 'SUGARCULT', 'RFID', 'SWIPE', '30X', 'HOUSE''S', 'BI-WAY', 'BLYTHE,CA', 'REDDER', 'PLUMPER', 'LEFTWINGERS', 'WHINGE', 'ANNOYING..!!1', 'SENSORY', 'ADHD/ODD', 'ZYBAN', 'RAMP', 'SUB-WOOFER''S', 'TATTOOIST', '477', 'SOFISTCATED', 'B/J', 'ALLURE', 'THIS?(SEE', 'PAKISTANIS:DO', 'PLEASE?I', 'CLASHING', 'KNOW(DOCS', 'WHITESMOKE', 'SCREEN''S', 'SPINK', 'YOUI', 'DELICATE', 'MISDIAGNOSED', 'DIPERNO', 'HIM.PLEASE', '45CM', '35CM', 'ENOUGHT', 'DECIMETERS?PUT', 'RDMB', 'HOMELOANS', 'HAA', 'ORIGIANL', 'RESTON', 'ZINNIAS', 'PERENNIAL', 'WHOOPIE', 'CUSHIONS', 'POOFS', 'CAT,ITS', 'TIME,ITS', 'TUXEDOS', 'CHICKAN', 'WHISLE', 'RUMBLING', '7LEVELS', 'YOUFROM', 'CEMO', 'RECURRENT', 'LARYNGEAL', 'W/NO', 'SOUCRE', 'COMMA', 'WORDCUB', 'WOMEN:HAVE', 'PIGGYBACK', 'ANOLE', 'CHRISTIANSEN', 'SWEEPSTAKES,GETTING', 'WON.HOW', 'EUDORA5.1', 'EXPRESS,NETSCAPE4.X', '6.X', '''COURT', 'WISK''', '4/13', '50-70', 'DAUGHTER,CAN', 'UVULA', '''AYURVEDA''', 'ACUPUNTURE', 'BAJA', 'REASONIBLE', 'PUZZY', 'SORCERER', 'DISEASES/SICKNESS', 'ANUS/RECTUM?CAN', 'HOME?WHAT', 'COCETH', 'KELLOGGS', 'DAISUKE')

result:

2

Added

CREATE TABLE [dbo].[WordDictionary](
[Word] [nchar](30) NOT NULL,
[Count] [int] NOT NULL,
    CONSTRAINT [PK_WordDictionary] PRIMARY KEY CLUSTERED 
    (
      [Word] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     
       ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
like image 771
Noam Shaish Avatar asked Apr 24 '11 13:04

Noam Shaish


People also ask

Can we use in for string in SQL?

The IN operator can be used to compare a string column (char, nchar, varchar, nvarchar) to a list of strings. The SQL commands below shows 2 functionally equivalent queries – one that uses multiple arguments and a second that uses the IN operator.

Can substring be used in WHERE clause?

The SUBSTRING SQL function is very useful when you want to make sure that the string values returned from a query will be restricted to a certain length. In the following example, using the 'firstname' column, the last two characters are matched with the word 'on' using the SQL SUBSTRING function in the where clause.

What is like %% in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.


2 Answers

Your IN list contains the item '²'.

I'll be very surprised if that isn't the source of the issue (though it doesn't actually match for me under my default collation)

like image 112
Martin Smith Avatar answered Oct 22 '22 15:10

Martin Smith


Try making the strings in the IN() clause Unicode by prefixing with N

IN (N'Id1', N'Id2',...)
like image 38
Christo Avatar answered Oct 22 '22 15:10

Christo