🧚 Ακούστε! Το Beekeeper Studio είναι ένα γρήγορο, μοντέρνο και ανοιχτού κώδικα GUI βάσης δεδομένων Λήψη
April 11, 2023 Από Beekeeper Studio Staff

Often developers need to write a stored procedure that returns a resultset filtered based on input parameters. One solution is to use the EXECUTE command passing a SQL strings made by concatenating a SELECT statement with a WHERE clause. The EXECUTE command does the job but it is limited in the following areas:

  • Patching complex conditions in the WHERE clause can get cumbersome.
  • The SQL string passed to the EXECUTE command runs in its own memory space, hence it doesn’t share the same settings used by the main batch.
  • The server cannot optimize the patched SQL like it does regular batches.

One solution to replace the EXECUTE command is to use the ISNULL function. The following stored procedure queries the orders table and returns a resultset based on the parameters provided. If null is passed in the parameter, the procedure will ignore it:

orders Table

OrderID Name Price
345 John Doe 400
346 John Doe 450
347 Mark Smith 400
USE orders_database

CREATE PROCEDURE [DBO].[order_filter]
@name CHAR(10),
@price INT
AS
SELECT *
FROM orders
WHERE name = ISNULL(@name, name)
AND price = ISNULL(@price, price)

Run this SQL script from the SQL window in Teratrax Database Manager to create the stored procedure. Replace every thing in lower case with your own.

Try running this procedure in the following scenarios (replace parameters to match your own criteria):

EXECUTE order_filter 'John Doe', null
EXECUTE order_filter null, 400
EXECUTE order_filter null, null

Το Beekeeper Studio Είναι Ένα Δωρεάν & Ανοιχτού Κώδικα GUI Βάσης Δεδομένων

Το καλύτερο εργαλείο SQL query & editor που έχω χρησιμοποιήσει. Παρέχει όλα όσα χρειάζομαι για να διαχειριστώ τη βάση δεδομένων μου. - ⭐⭐⭐⭐⭐ Mit

Το Beekeeper Studio είναι γρήγορο, διαισθητικό και εύκολο στη χρήση. Το Beekeeper υποστηρίζει πολλές βάσεις δεδομένων και λειτουργεί εξαιρετικά σε Windows, Mac και Linux.

Η έκδοση Linux του Beekeeper είναι 100% πλήρης, χωρίς περικοπές και χωρίς συμβιβασμούς στα χαρακτηριστικά.

Τι Λένε Οι Χρήστες Για Το Beekeeper Studio

★★★★★
"Το Beekeeper Studio αντικατέστησε εντελώς την παλιά μου ροή εργασίας SQL. Είναι γρήγορο, διαισθητικό και κάνει τη δουλειά με βάσεις δεδομένων απολαυστική ξανά."
— Alex K., Προγραμματιστής Βάσεων Δεδομένων
★★★★★
"Έχω δοκιμάσει πολλά GUIs βάσεων δεδομένων, αλλά το Beekeeper βρίσκει την τέλεια ισορροπία μεταξύ χαρακτηριστικών και απλότητας. Απλά δουλεύει."
— Sarah M., Full Stack Μηχανικός

Έτοιμοι να Βελτιώσετε τη Ροή Εργασίας σας με SQL;

download Δωρεάν Λήψη