Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my stored procedure:

SQL
CREATE PROCEDURE DuplicationCheckAccountLedger (IN aname varchar(50), OUT errflag bit, OUT errFieldName varchar(10))
BEGIN
	declare cnt int default 0;
	select count(name) into cnt from account_ledger where name = aname;	
	if cnt = 0 
	then		
		set errflag = 0;
		set errFieldName = 'none';
	else 
		set errflag = 1;
		set errFieldName = 'name';
        end if;
end //


Instead of passing name field as 'aname', I would like to pass it as 'name' only. The query would like to read as:
select count(name) into cnt from account_ledger where name = name;

But, I know there is some problem with the above query that left hand side and right hand side will always be equal since select query will refer to table's field for both.

Is there any prefix to be used for such scenarios like something 'this' operator as we use in c#?

What I have tried:

I tried googling for this thing.. but I am not finding a good keyword to search for this query.
Posted
Updated 4-Oct-16 23:46pm

1 solution

Use dot notation for table fields:

SQL
select count(1) into cnt from account_ledger where account_ledger.name = aname;	
 
Share this answer
 
Comments
Member 11040029 5-Oct-16 7:03am    
Hi John, dot notation would parse left hand field as a table field but the field on the right hand side the 'name' field will also be parsed as the field of the same table instead as a parameter.
I would like to have select query as:
select count(1) into cnt from account_ledger where account_ledger.name = name;
insted of
select count(1) into cnt from account_ledger where account_ledger.name = aname;

my column name and variable names are same.
Here is the table structure:
create table account_ledger
( id mediumint primary key,
name varchar(50) unique key
)Engine = innodb charset = utf8;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900