Pass select result as parameter of stored procedure

1.One way is: a) Declare your variables b) Assign values to them with a single select statement c) Execute the procedure passing the local variables d) Execute the following in a loop using WHILE or CURSOR in order to apply this for all rows in TABLE1 DECLARE @param1 <DATATYPE>, @param2 <DATATYPE>, … SELECT TOP 1 … Read more

How to print DateTime variable in the RAISERROR method?

The supplied value must be a constant or a variable. You cannot specify a function name as a parameter value. (from MSDN Executing Stored Procedures). You need to do something like this: declare @EffectiveStartDateText varchar(30) set @EffectiveStartDateText = cast(@EffectiveStartDate as varchar) declare @EffectiveEndDateText varchar(30) set @EffectiveEndDateText = cast(@EffectiveEndDate as varchar) RAISERROR ( ‘SPName: InsertUpdateLiquidityDateRule: Start … Read more

Call a stored procedure for each row returned by a query in MySQL

Concepts such as “loops” (for-each, while, etc) and “branching” (if-else, call, etc) are procedural and do not exist in declarative languages like SQL. Usually one can express one’s desired result in a declarative way, which would be the correct way to solve this problem. For example, if the testProc procedure that is to be called … Read more

Optional argument in PL/pgSQL function

Since PostgreSQL 8.4 (which you seem to be running), there are default values for function parameters. If you put your parameter last and provide a default, you can simply omit it from the call: CREATE OR REPLACE FUNCTION foofunc(_param1 integer , _param2 date , _ids int[] DEFAULT ‘{}’) RETURNS SETOF foobar — declare return type! … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)