Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 14:30

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[SQL] BETWEEN bei varchar Spalten

Discussion on [SQL] BETWEEN bei varchar Spalten within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
Legithos's Avatar
 
elite*gold: 95
Join Date: Nov 2009
Posts: 669
Received Thanks: 47
[SQL] BETWEEN bei varchar Spalten

Hallo zusammen,

ich habe mal wieder n kleines Problemchen in meinem Code.

Ich habe eine Tabelle 'table' mit einer Spalte 'column'. Die Spalte ist vom Typ varchar und dort werden verschiedene Werte gespeichert. Die verschiedenen Werte können Ganzzahlen (zb ein Alter) oder aber auch ein String (zb ein Name) sein.

Falls in 'column1' eine Zahl steht, würde ich gerne von einer SQL-query alle Einträge zwischen zwei Eingaben von zwei Inputfeldern haben.

Beispiel:

HTML Code:
<input type='text' name='value1'> und <input type='text' name='value2'>
Ich will nun alle Einträge in meiner Tabelle 'table' und der Spalte 'column', die zwischen meinen Input-Eingaben liegen.

Code:
$pdo->prepare("SELECT column FROM table WHERE column BETWEEN :value1 AND :value2");
$stmt->execute([
   'value1' => $_POST['value1'],
   'value2' => $_POST['value2']
]);
Prinzipiell nicht wild und eigentlich relativ simpel .. NUR funktioniert es so nicht. Ich denke mal es liegt daran, dass zwar in der 'column' eine Ganzzahl steht (das Alter), die Spalte jedoch vom Typ ein Varchar ist.

Was ich bisher probiert habe:
  • Mit 'column' als Typ int statt varchar ausprobiert und es funktioniert. - Nur fällt hier das Speichern der Strings - zb Namen flach.
  • Casten in der SQL Query mit CAST('column' AS INT) oder CONVERT(INT, column). Ich habe auch schon versucht die value's als varchar zu casten.
  • BETWEEN durch <= und >= ersetzt.

Mir ist bewusst, dass es besser ist, Spalten entweder für Zahlen oder für Strings zu nutzen. In meinem aktuellen Projekt ist dies leider nicht möglich, da die Spalte variabel genutzt werden muss.

Vielen Dank schonmal,
Legithos
Legithos is offline  
Old 08/07/2020, 12:22   #2


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,118
Received Thanks: 2,435
Sowohl mit between als auch mit Operatoren funktioniert es ohne Probleme.

Between:
Mit Operatoren:
False is offline  
Thanks
1 User
Old 08/07/2020, 13:25   #3
 
Legithos's Avatar
 
elite*gold: 95
Join Date: Nov 2009
Posts: 669
Received Thanks: 47
Hat mir schon geholfen. Das Problem war, dass ich in meinem richtigen Code folgendes PDO Array hatte:

Code:
$stmt->execute([
   'value_1' => $_POST['value1'],
   'value_2' => $_POST['value2']
]);
Das funktioniert nicht. Er kommt mit dem _ durcheinander. Habs ohne den _ gemacht und es funktioniert einwandfrei. Danke !
Legithos is offline  
Reply


Similar Threads Similar Threads
Question about Database Varchar vs Int
09/27/2018 - Flyff Private Server - 5 Replies
I would like to ask about database here. Let's just say i've added a datatype in DBManager in the source which is SQL_PARAM_INPUT, SQL_C_LONG, SQL_VARCHAR and i wrote a datatype INT in my Character_TBL Is there gonna be a problem about the saving of data?
[FIX] SQL Error to convert Varchar in Datetime
04/12/2016 - Shaiya PServer Guides & Releases - 13 Replies
Hi many guys asked me why they were getting in their log, the SQL error: error to convert "Varchar in Datetime", so i took a look on EPvPers and i didn't see (maybe i'm wrong o.o) any post with the problem solved. It happens with Warehouse dcing when trying to store items or the notice board ! It's not really a Fix but more a specific attention to pay on SQL configurations. SQL maybe tried to save the datas in a wrong date format ! To check if you're in this case, run the next query:
Error Convert varchar in datetime
03/24/2015 - Shaiya PServer Development - 2 Replies
Bonjour Error Log (query=EXEC usp_Insert_Action_Log_E): 2015-03-19 12:39:14 err=-1, Erreur de conversion du type de données varchar en int., SQL STATE: 42000, NATIVE ERROR: 8114 (0x1FB2) 2015-03-19 12:39:14 DBWrite::LogGame: err=-1, query=EXEC usp_Insert_Action_Log_E 'test',1,1,'test', 70,390007982,0, 1873.809692,14.679998,351.206665, '2015-03-19 12:39:14' ,114, 4388416769224671232,36196,0,1,62100,1993293200,NUL L,NULL,NULL,NULL,'Chaussures Syrons','0,0,0,0,0,0...
Varchar to datetime error
06/19/2013 - Shaiya PServer Development - 5 Replies
Hi, everyone... to the point.... I'm having some problems with mi warehouse and item mall, all the problems are because varchar cannot convert into datetime (I THINK) and I'm getting sick of searching in others post because anything works :( so... here are my logs. Hope somebody could help me... please please :handsdown: If somebody knows how to fix this, I'll be grateful if he explains me detailed and sloooooooowly please :p PS_GAME__system log start (Game01) 2013-06-18 22:30:05...
[SQL]2 Spalten vergleichen
05/28/2012 - General Coding - 2 Replies
Guten Morgen, ich habe in einer Tabelle 2 Spalten time verfall nun möchte ich mir alle Einträge suchen, bei denen die Spalte "time" >= die Spalte "verfall" ist.



All times are GMT +2. The time now is 14:30.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.