Einzelnen Beitrag anzeigen
  #6  
Alt 22.11.2010, 20:26:02
-sensemann- -sensemann- ist offline
Anfänger
 
Registriert seit: Sep 2010
Alter: 58
Beiträge: 37
AW: Spalte prüfen.

PHP-Code:
DELIMITER //
CREATE FUNCTION count_substring(p_sVar VARCHAR(100), p_sSep VARCHAR(10) )
RETURNS INT
LANGUAGE SQL
BEGIN
DECLARE v_i INT;
DECLARE 
v_length INT;
DECLARE 
v_count INT;

SET v_length := LENGTH(p_sVar);
SET v_i := 1;
SET v_count := 0;

WHILE (
v_i <= v_length) DO
IF 
SUBSTRING(p_sVar,v_i,1) = p_sSep THEN
SET v_count 
:= v_count +1;
END IF;
SET v_i := v_i +1;
END WHILE;
RETURN 
v_count;
END$$

DELIMITER ;

SELECT `products_model`, count_substring(products_userfield_2,';') AS anzahl_sep from products
where count_substring
(products_userfield_2,';') > 3
order by 
`products_model
bringt folgendes :

SQL-Befehl: Dokumentation

SELECT `products_model` , count_substring(
products_userfield_2, ';'
) AS anzahl_sep
FROM products
WHERE count_substring(
products_userfield_2, ';'
) >3
ORDER BY `products_model`
LIMIT 0 , 30

MySQL meldet: Dokumentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(products_userfield_2,';') AS anzahl_sep from products
where count_substring(pro' at line 1

???
Mit Zitat antworten