How can I pass the same input to all sql files only once at the beginning?

I call 4-5 scripts at once from a file. But I only need to provide one input to the file in the first sql I call.

This input will be the input for all other sql files that I called after the first one.

Is there a way to do this?

Please, help.

0


source to share


4 answers


I think you can achieve what you want using sqlcmd and variables utility . The last link states that you can use environment variables as well.



+1


source


Do you mean:

query2 is based on the result of query1, query3 is based on the result of query2, etc.

If so, you can use views for



create view view1 as select * from table1;
create view view2 as select * from view2;
create view view3 as select * from view3;
create view view4 as select * from view4;
select * from view4

      

Of course, you have to add the where clause yourself.

See sections http://dev.mysql.com/doc/refman/5.0/en/create-view.html for details

0


source


no START fbm.sql START fba.sql START fei.sql START fbe.sql START fae.sql START tfat.sql START ins_FBH.sql this is the code.

in fbm.sql I have input code like bill id = '& 1'. also i have the same account id input in other sql.

but i run master sql and it will run fbm.sql and ask me to enter account id. suppose I give it "ABC" and again after completing this fbm.sql it again asks me to enter the account id for fba.sql which I no longer want to give n again. Wat I want this fba.sql and other relevant sql to accept the input account id as "ABC" without typing it.

0


source


Have you ever thought about using a stored procedure for this. It depends on MySQL version 5.0 (or later) of course. But it allows you to define variables and use them within a procedure, very flexible and easy to use! Caveat, haven't experienced this myself, my experience with Oracle PL / SQL but the concepts are similar.

Then you can do things like this (from the MySQL newsletter:

http://www.mysql.com/news-and-events/newsletter/2004-01/a0000000297.html

DELIMITER // [1]

CREATE PROCEDURE payment [2]
(payment_amount DECIMAL(6,2),
payment_seller_id INT)
BEGIN
DECLARE n DECIMAL(6,2);
SET n = payment_amount - 1.00;
INSERT INTO Moneys VALUES (n, CURRENT_DATE);
IF payment_amount > 1.00 THEN
UPDATE Sellers
SET commission = commission + 1.00
WHERE seller_id = payment_seller_id;
END IF;
END;
//

      

0


source







All Articles