Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenation inside SQL statement

Status
Not open for further replies.
Jan 26, 2001
550
GB
Hi Guys

I am writing a SQL statement to extract all items from a database, where the items ID is contained within a delimited list, but i can't get it to work.

the string is something like {1},{2},{5},{7}

so the statement i need is something like

SELECT * FROM ITEMS WHERE '" & IDString & "' LIKE ITEM_ID

but this doesnt work. Even if it did work i would need to surround the item id by {'s to avoid any number being returned as true just because it appears within another number e.g. ID 131 would return true for ids 1 and 3 unless surrounded by brackets.

I can accomplish the same effect easily enough by selecting all items and filtering them via ASP but i would much prefer selecting just the matching items via the SQL.

Does anyone have any suggestions?

Thanks alot

Nick

Nick (Webmaster)

 
the IN keywork uses a comma separated list

Code:
SELECT * FROM myTable WHERE idField IN (1,2,5,7,9,120,230)

If the entire number doesn't match, it won't be returned

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top