I am trying to create a Jenkins script using a SQL query with variables that are parameters in Jenkins. I need to use an insert using a select statement, a variable, and a static number. How can I create this query?
I have the select statement that will need to be used in the insert working:
SELECT uid FROM client_template.user
WHERE TYPE = 0 AND ACTIVE = 1
AND uid NOT IN (45,58,1331,1793,1807,2713);
However, I am unsure how to fit the above query into one that will work like this (Values 1234 & 1 -- correspond to did & urid):
INSERT INTO client_schema.user_role_roles (did, urid, uid)
VALUES (1234, 1)
SELECT uid FROM client_template.user
WHERE TYPE = 0 AND ACTIVE = 1 AND uid NOT IN (45,58,1331,1793,1807,2713);
Your question isn't totally clear, but if you are trying to use the select statement to select the uid
to use as the third parameter in your INSERT
then try:
INSERT INTO client_template.user_role_roles (did, urid, uid)
SELECT TOP 1 1234, 1, uid FROM client_template.user
WHERE TYPE = 0 AND ACTIVE = 1 AND uid NOT IN (45,58,1331,1793,1807,2713);
Note that your static values 1234
and 1
are simply listed as constants in your SELECT
subquery.
You should add the literal/constant value in the corresponding position in select
INSERT INTO client_schema.user_role_roles (did, urid, uid)
SELECT 1234, 1, uid
FROM client_template.user
WHERE TYPE = 0
AND ACTIVE = 1
AND uid NOT IN (45,58,1331,1793,1807,2713);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.