473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

If Condition in SQL to search

112 100+
I have textbox in application. If user type in text box it will search in the table. It basically ItemId

here is my code

Select top 1000 ima_itemid as ItemID, ima_itemName as ItemName from ima
where (ima_itemid LIKE @IMA_ItemID+'%')

This code is work fine.

Some users need to search more specific in the text box

Example: 110%1

If user type this id it need to select like 1101 _ _ 11, 110_ _ _21, 110 _ _ 61 etc.,

So i used if condition on the sql statement, but it doesnt work

If @IMA_ItemID= N'%'
then
Select top 1000 ima_itemid as ItemID, ima_itemName as ItemName from ima
where (ima_itemid LIKE @IMA_ItemID)
Else
Select top 1000 ima_itemid as ItemID, ima_itemName as ItemName from ima
where (ima_itemid LIKE @IMA_ItemID+'%')

It means If the user type with' % ' the in my statement i need to remove. If user type only numbers the i want to include. I think i need to do with programming. But i hope we can do also in the sql statement



Thanks in advance ur answer
Apr 10 '08 #1
2 2495
code green
1,726 Expert 1GB
You are trying to increase the power of your search engine,
but you have to think - where else have I seen this power?
It is synthesised by a "Search within results option"
This can be achieved mostly in SQL by creating a temporary table.
Another option, this is just a thought, but what about two text boxes?
Apr 10 '08 #2
debasisdas
8,127 Expert 4TB
Are you trying to use IF directly is part of SQL statement ?

It is better not to let the user enter % from frontend.
Apr 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kendal Goodrich | last post by:
In the setup project I am trying to create, I am wanting to search to see if DirectX 8 is installed on the local machine. I figured the best way to determine would be a registry key search, so I...
2
by: Branko | last post by:
Hello all, I have 2 columns and I search rows with two conditions. SELECT * FROM table WHERE A = '$a' AND B = '$b' How can I make mysql search columns with A condition first and after that...
1
by: Joel | last post by:
As my registry start condition was working fine, now it's not working anymore Here are the kind of parameter I use in VSNEt2003: A) Registry : Name : Pipo; Property : PROP1; RegKey...
1
by: James | last post by:
Access 2003, trying to count the number of records that meet a criteria. According to Help: "In the Database window, click Queries under Objects, and then click New on the database window...
2
by: alain.hogue | last post by:
I have a table "tblCards" with a field "Titre" that contain french words (Hébert, Gagné, Hélène, etc....) in an database with SQLEXPRESS 2005. I have used the asp:SqlDataSource to filter the...
4
by: joh12005 | last post by:
Hello, i posted for suggestions a little idea even if it still needs further thoughts but as i'm sure you could help :) if would like to implement some kind of Condition class which i coud...
0
by: Rob R. Ainscough | last post by:
I'm pretty frustrated right now, but I'm unable to get a Launch Condition to work at all in my Condition statement of a Registry entry. (working on a Deployment Project) 1. In Launch...
3
by: Don | last post by:
I've added a Setup and Deployment project to my Visual Studio 2005 Windows Application solution and have several OCX and DLL files that will be installed. But I can't seem to find any examples in...
7
by: pbd22 | last post by:
Hi. I really need some advice on fine-tuning a stored procedure that is the meat of the search logic on my site. Customers are allowed to save searches, which dumps the search logic in a table...
0
by: ashishyadav2007 | last post by:
In Setup project for .net I have added a dialog(form) between Start and End dialog(form), but i need to show that dialog(form) only if a registry search condition is successful. If registry search...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.