Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I give this codes to my project in SQL query but doesn't work:

SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like @serial + '%'


I use VS 2008 and database access 2007
Posted
Updated 12-May-10 2:37am
v2

serial is obviously a string(nvarchar) so you need to place it in quotes.

WHERE serial like '\' + @serial + '%'

Sorry, this is for SQL
In code use

string.format("WHERE serial LIKE '{0}%'", @serial)
 
Share this answer
 
v2
Comments
Sandeep Mewara 12-May-10 8:51am    
I didn't get it why you need to put '' (back slash) before it. How is it placing it in quotes?
Update: Backslash is getting auto-removed so wrote in words.
[no name] 12-May-10 8:51am    
It says: Error in WHERE clause near '@'
Unable to parse query text
What is the value of @serial you are providing. Update that in your question. Syntax to me looks correct.

For SQL:
For verification try this if its work fine:
SQL
DECLARE @serial varchar(10)
SET @serial = 'A'

SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like @serial + '%'


For Code:
C#
string serialThatStartWith = "S";
string myQuery = string.format("SELECT serial, company_name FROM (Sometable)WHERE serial LIKE '{0}%'", serialThatStartWith);
 
Share this answer
 
v2
Comments
[no name] 12-May-10 9:16am    
he value of @serial is string
Try surround this like with "".

C#
String.Format(" SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like '{0}%'", serial)


I don't know if i have typed it right but You should get the idea
 
Share this answer
 
v2

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