Avatar billede mnoer Nybegynder
27. august 2006 - 12:45 Der er 7 kommentarer

søgning

Når jeg laver et SQL statement hvor man kan søge på forskellige ting kan jeg ved text-typer bare indtaste % for at den skal acceptere alle resultater.
Men hvad gør jeg med number-typer for at opnå samme resultat? (her kan jeg jo ikke bruge like søgning)
Avatar billede terry Ekspert
27. august 2006 - 15:57 #1
Try using Like '*1*'
Avatar billede terry Ekspert
27. august 2006 - 15:58 #2
wher 1 is the number you are looking for
Avatar billede mnoer Nybegynder
27. august 2006 - 18:44 #3
Not the answer I was looking for...
If we say I have 2 columns streetName (text) and number (number)
If I want to search for all rows where the number is ie. 5 the SQL could be "select * from Table where number = 5 and streetName like '%'" (this way streetName can be anything)

But what if I want to search for all rows where streetName starts widt "Ba" (and not care about number) "select * from Table where streetName like 'Ba%' and number ???" (I don't want to just exclude number from the select statement)
Avatar billede terry Ekspert
27. august 2006 - 19:46 #4
"... (and not care about number)" So any number is valid?

Then exclude the number from the the where.

"select * from Table where streetName like 'Ba%'"

"... (I don't want to just exclude number from the select statement)"

Not sure what you mean here. If number can be anything then it isnt normal that you would use it in your WHERE.
Avatar billede terry Ekspert
27. august 2006 - 19:53 #5
Have you tried "select * from Table where streetName like 'Ba%' and [number] Like '%'"
Avatar billede mnoer Nybegynder
27. august 2006 - 20:12 #6
Yes I have tried that, and it is not possible to do a LIKE search on a number-type column. The reason why I don't want to exclude it from the statement is that it is not required that you fill all search-fields (but you have the option) and I want to use the same SQL statement.
Avatar billede terry Ekspert
27. august 2006 - 20:20 #7
In Access it is possible to use like with number fields, but if you rfor example using VB.NET then I'm not sure.

I would build the SQL dynamically depending on what fields are entered.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester