Loops? #306
-
Want to implement a loop function so I can make a variable number of data entry points(typed by user) in a form. Does not seem as any loops are usable/available. Using this to connect to a testing database, based on the number of values needed per test. Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Hello and welcome to SQLPage! sql is a declarative language. it doesn't have loops. However, what you want to do is definitively possible to express in sql using a recursive common table expression select 'form' as component;
WITH RECURSIVE InputFields AS (
SELECT 1 AS i
UNION ALL
SELECT i + 1
FROM InputFields
WHERE i < $number_of_fields::int
)
SELECT 'Input field ' || i AS name
FROM InputFields; |
Beta Was this translation helpful? Give feedback.
-
Adding to this, I am wondering how I could insert the data from My from into the database after submission. Using the same WITH statement? |
Beta Was this translation helpful? Give feedback.
Microsoft SQL Server does indeed support recursive CTEs, but not the keyword "recursive".