SQL Server - Substring in the query
Asked By alice wonder
28-Aug-06 03:10 PM
" Select * from tblPA where SerialNo LIKE '(@txtSearchSerialNo)%'" ;
I want the query to return values for all the matches typed in the txtbox named "txtSearchSerialNo"
If I replace 'X%' Instead of '(@txtSearchSerialNo)%'" I get few serch results.
I have the following code.
SqlConnection celPwrConnection = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=CP");
string Cmd = " Select * from tblPA where SerialNo LIKE '(@txtSearchSerialNo)%'" ;
SqlCommand Cmd = new SqlCommand(Cmd ,celPwrConnection);
Cmd.Parameters.Add(new SqlParameter("@txtSearchSerialNo", SqlDbType.VarChar,50, "txtSearchSerialNo"));
Cmd.Parameters["@txtSearchSerialNo"].Value = txtSearchSerialNo.Text.ToString();
celPwrConnection.Open();
SqlDataReader dr = Cmd.ExecuteReader();
DataGridSearch.Visible=true;
DataGridSearch.DataSource = dr;
DataGridSearch.DataBind();
celPwrConnection.Close();
Thanks.
Remove Parenthesis
Try removing the parenthesis, as follows:
string Cmd = " Select * from tblPA where SerialNo LIKE '@txtSearchSerialNo%'" ;
If that doesn't work, try this:
string Cmd = " Select * from tblPA where SerialNo LIKE @txtSearchSerialNo + '%'" ;
Thanks
Tried this before "did not WORK"
string Cmd = " Select * from tblPA where SerialNo LIKE '@txtSearchSerialNo%'" ;
This "WORKED"
string Cmd = " Select * from tblPA where SerialNo LIKE @txtSearchSerialNo + '%'" ;
Thanks for your time and help.
You have to do it like this
select @txtSearchSerialNo = '%' + @txtSearchSerialNo + '%'
select *
from tableA where somecolumn like @txtSearchSerialNo
XML limits in SQL / Server? SQL Server I'm trying to apply techniques I'd normally use to pull data from SQL / Server to pull XML from SQL / Server, and I'm running into a problem. Here's what I'm doing: 1. I
Why_can’t_recursive_queries_contain. . .? SQL Server hi I hope I didn = 92t put too many questions 1) Why can = 92t recursive queries also be unioned together with UNION operator ( instead they must use UNION ALL )? thanx SQL Server Programming Discussions SQL Server 2008 (1) SQL Server 2005 (1) SQL Server 2000 (1) SQL Server (1) Oracle (1) Ruby (1) MichaelcoAToptonlineDOTnet (1
DBCC Memorystatus Results across a linked server SQL Server declare @lnvc_SQL nvarchar(4000) select @lnvc_SQL = N'select * from openquery([HQAPPSQL04], ''set fmtonly off; ' + ' exec lnvc_SQL Does anyone know why this only returns 1 result and not all of them? SQL Server Programming Discussions Microsoft.SqlServer.Server.SqlProcedure (1) SQL Server 2008 (1) SQL Server 2000 (1) SQL Server (1) Microsoft.SqlServer.Server (1) System.Data
Timeouts after periods of inactivity in server SQL Server Hello All, I have 3 servers with sql server 2005 sp2 running each on win 2003 server. Each sql server instance has a copy of the same database. Load balancing spreads the load in these
sp_trace_getdata: non-blocking read & interpreting event boundary? SQL Server Hii all! I am developing some functionality based on SQL Server tracing. The first iteration used SQL Server traces which recorded events to files and I read those traces using the SQL Server libraries (TraceFile). In the next iteration I am looking into removing intermediate trace files produced