MySQL Forums
Forum List  »  Newbie

Help with concat
Posted by: Russel James
Date: September 03, 2016 02:26PM

Hi folks,

I have the following sql inside a sproc that works fine.


SET @t = p_tbl;
SET @v = p_vesselID;;
SET @p = p_period;


SET @s = CONCAT("SELECT * FROM ", @t, " WHERE vesselID = ", @v , " AND period >= ", @p, " ORDER BY pKey");

PREPARE stmt FROM @s;

EXECUTE stmt;


Instead of Selecting all the fields (SELECT *) I just want to select certain fields (SELECT ledger.vesselID, ledger.amount FROM ledger...). How do I write it so that I can include the tableName @t.

Something like:
SET @s = CONCAT("SELECT , @t, ".vesselID, ", @t, ".amount " FROM ", @t, " WHERE vesselID = ", @v ,

But the above sql does not compile.
Any ideas ?

Thanks

Options: ReplyQuote


Subject
Written By
Posted
Help with concat
September 03, 2016 02:26PM
September 03, 2016 06:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.