| Author: mythili d 04 Sep 2008 | Member Level: Silver | Rating: Points: 2 |
I do not understand it correctly are you saying that all the three state names are in one text box and they are seperated by commas
Please try this example declare @sql nvarchar(1000) declare @loc varchar(100) set @loc=('chennai,madrass,kochi') set @sql=('select *from tblItem where location=''' +@loc+'''') print @sql exec @sql Hope this helps.
|
| Author: Geetha 05 Sep 2008 | Member Level: Gold | Rating: Points: 3 |
public DataTable GetKeywordList(strDBConn) { SqlConnection sqlCon = new SqlConnection(strDBConn); SqlCommand sqlCmd = new SqlCommand(); DataTable dtKeyword = new DataTable(); try { sqlCmd.Connection = sqlCon; sqlCmd.CommandText = "Select * from Citylist where city = '" + txtCity.Text +"'"; sqlCon.Open(); SqlDataAdapter daFile = new SqlDataAdapter(); daFile.SelectCommand = sqlCmd; daFile.Fill(dtKeyword); return dtKeyword; } catch (Exception ex) { throw ex; } finally { if (sqlCon.State == ConnectionState.Open) sqlCon.Close(); } }
|
| Author: Lakhan Pal 05 Sep 2008 | Member Level: Gold | Rating: Points: 3 |
Write Query Like This: DECLARE @SQLQUERY VARCHAR(200) SET @SQLQUERY='Select * from Citylist where city IN ('+TextBoxValue+') EXEC (@SQLQUERY)
|
| Author: @@@ Hyderabadi Biryani @@@ 05 Sep 2008 | Member Level: Diamond | Rating: Points: 6 |
Hi, User is going to enter 3 cities in one single text box or you have combox box in UI which you can use to select multiple cities?
The finaly query should be if it is single text box.
SELECT * FROM STATES WHERE ( CITY_NAME LIKE '%MADRAS%' OR CITY_NAME LIKE '%HYD%' OR CITY_NAME LIKE '%BOM%' )
If it is List Combobox then
SELECT * FROM STATES WHERE city_name in ('X','Y','Z')
Thanks -- Vj http://dotnetvj.blogspot.com
|