Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,

I have a table tblTest where I am saving category id like (1,2,3,4). category id is integer but user can select more than one category. So i want to get category name from this string like (category A,category B, category C,..) . Have any idea for same?
Posted

you can select mutiple item by multiple id using 'in' clause in sql like this

SQL
SELECT * FROM tableName where id in (value1,value2,value3)
 
Share this answer
 
Comments
rummer 3-Jun-14 1:00am    
I know this query but this is a single string like ('1,2,3')
can't do this type?
SQL
SELECT CategoryId, CategoryName
FROM Categories
WHERE CategryId IN (1,2,3)

or

SQL
SELECT CategoryId, CategoryName
FROM Categories
WHERE CategryName IN ('Category A','Category B','Category C')
 
Share this answer
 
Comments
rummer 3-Jun-14 0:59am    
I know this query but this is a single string like ('1,2,3')
can't do this type?
rummer 3-Jun-14 0:59am    
DECLARE @STRING VARCHAR(300)
SET @STRING = '1,2'

SELECT * FROM [ATS_NEW].[dbo].[tbl_Category] WHERE catid IN (@STRING)


Error- Msg 245, Level 16, State 1, Line 4
Conversion failed when converting the varchar value '1,2' to data type int.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900