Hi
First of all English is not my main language so if you don't understand something that I wrote please ask ;) Well to start....ToolStrip is searching columns of one table. Search is based by what is contained in one of the columns. Currently my query looks like this:
SELECT Uplatilac, [Svrha uplate], Primalac, [Šifra plaćanja], Valuta, Iznos, [Račun primaoca], Model, Broj
FROM Uplata
WHERE Uplatilac LIKE @Uplatilac
...and that works fine, but only if I write in ToolStrip's textbox whole word or words that are in column Uplatilac. What I want is that user can find what he is looking for by writing just couple of letters. For example if he searches for John Doe only thing that he needs to do is to write John and he will get table with column Uplatilac = John Doe and of course any other that starts with John. I tried to modify LIKE part like this:
LIKE '%'+@Uplatilac+'%'
but it still doesen't work. One more thing. I am doing this in C# and I got also problem with report. When trying to print I can only print first data that is written in table (I don't know how to explain this better but it is done with BindingNavigator). And again if you can't completly understand what am I saying please ask. Tnx in advance...
Problem with ToolStrip query
Started by DisturbeD, Sep 24 2008 10:10 AM
10 replies to this topic
#1
Posted 24 September 2008 - 10:10 AM
|
|
|
#2
Posted 24 September 2008 - 11:49 AM
the + isn't working in sql as a concatenor far as I know. you need to do that addition in your C#, or do a
concat('%', @Uplatilac, '%') in your query.
Edited by Orjan, 24 September 2008 - 12:45 PM.
added a [code]
#3
Posted 24 September 2008 - 11:54 AM
orjan said:
the + isn't working in sql as a concatenor far as I know. you need to do that addition in your C#, or do a concat('%', @Uplatilac, '%') in your query.
It works for sure.....well at least that's what my professor at my highschool told me :D
#4
Posted 24 September 2008 - 12:44 PM
well, you said it didn't work *smile*
anyway, I think it might work in T-SQL, microsoft's addon to stored procedures on MS SQL Server. It does NOT work in MySQL ver 5.0 at least. but the concat version works there.
anyway, I think it might work in T-SQL, microsoft's addon to stored procedures on MS SQL Server. It does NOT work in MySQL ver 5.0 at least. but the concat version works there.
#5
Posted 24 September 2008 - 12:52 PM
Without knowing the DB platform you're using, it will be hard to help. Each DB has its own quirks.
#6
Posted 24 September 2008 - 01:51 PM
WingedPanther said:
Without knowing the DB platform you're using, it will be hard to help. Each DB has its own quirks.
MS SQL.....I thought that I wrote it..... :o
#7
Posted 24 September 2008 - 02:27 PM
yeah, in MS SQL it's meant to be working, when reading about it. but I'd say it's easier to add the %-signs before sending the statement to the query...
#8
Posted 24 September 2008 - 04:28 PM
orjan said:
yeah, in MS SQL it's meant to be working, when reading about it. but I'd say it's easier to add the %-signs before sending the statement to the query...
hmmm....I am not really following you here....what do you mean by adding % signs before sending the statement to the query??
#9
Posted 24 September 2008 - 05:15 PM
before sending the query to the server might sound better :-)
#10
Posted 25 September 2008 - 08:40 AM
Here is a solution if someone is interested in reading it :):
SELECT Uplatilac, [Svrha uplate], Primalac, [Šifra plaćanja], Valuta, Iznos, [Račun primaoca], Model, Broj
FROM Uplata
WHERE SUBSTRING(Uplatilac, 0, LEN(@Pretraga) + 1) LIKE @Pretraga
I haven't solve it on my own so if someone could explain me just last row, maybe few more words about SUBSTRING because i never used it before. And tnx to everyone who tried to help me.
SELECT Uplatilac, [Svrha uplate], Primalac, [Šifra plaćanja], Valuta, Iznos, [Račun primaoca], Model, Broj
FROM Uplata
WHERE SUBSTRING(Uplatilac, 0, LEN(@Pretraga) + 1) LIKE @Pretraga
I haven't solve it on my own so if someone could explain me just last row, maybe few more words about SUBSTRING because i never used it before. And tnx to everyone who tried to help me.
#11
Posted 26 September 2008 - 01:26 PM
hmm.. substring cuts out a piece of the first parameter from char #0 to char # (length of @Petraga)
if @Petraga is 6 chars long, it would cut out the 6 first characters of the content in Uplatilac and compare that to @Petraga
so this only works from start of the field in my head?
if @Petraga is 6 chars long, it would cut out the 6 first characters of the content in Uplatilac and compare that to @Petraga
so this only works from start of the field in my head?


Sign In
Create Account

Back to top









