473,670 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to append the string to SQL queries in stored procedure of Postgres....

10 New Member
i want to append the string which is present in the stored pocedure to SQL query

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key ==b.key';

for s in

select * from tbl_text1 a,tbl_test2 b where a.id==b.id and (want to append string tempapp here);

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';


can you help me regarding this........... ...its urgent

Regards
Shree
Dec 11 '07 #1
9 21871
rski
700 Recognized Expert Contributor
i want to append the string which is present in the stored pocedure to SQL query

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key ==b.key';

for s in

select * from tbl_text1 a,tbl_test2 b where a.id==b.id and (want to append string tempapp here);

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';


can you help me regarding this........... ...its urgent

Regards
Shree
Do it with execute

EXECUTE 'select * from tbl_text1 a,tbl_test2 b where a.id==b.id and '||tempapp;
I'm not sure if it works without EXECUTE
Dec 11 '07 #2
Shree111
10 New Member
Do it with execute

EXECUTE 'select * from tbl_text1 a,tbl_test2 b where a.id==b.id and '||tempapp;
I'm not sure if it works without EXECUTE

i didnt get result...but i have found an alternative way.....i have taken remaining query in a string variable and appended tht variable as u told...now its working...thank s.....

i have got another problem....want to take first parameter in a string variable and append that string in the execute query....its like follow---------

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key ==$1'; (its showing error here)
squery:='select * from tbl_text1 a,tbl_test2 b where '

for s in

execute squery || tempapp

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';

$1 value is not taking inside execute statement....ca n u help me out regarding this problem...its urgent
Regards
Shree
Dec 12 '07 #3
rski
700 Recognized Expert Contributor
i didnt get result...but i have found an alternative way.....i have taken remaining query in a string variable and appended tht variable as u told...now its working...thank s.....

i have got another problem....want to take first parameter in a string variable and append that string in the execute query....its like follow---------

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key ==$1'; (its showing error here)
squery:='select * from tbl_text1 a,tbl_test2 b where '

for s in

execute squery || tempapp

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';

$1 value is not taking inside execute statement....ca n u help me out regarding this problem...its urgent
Regards
Shree
maybe like this
tempapp:='a.key =='||$1
doesn't it work ?
If no what is the error message
Dec 12 '07 #4
Shree111
10 New Member
maybe like this
tempapp:='a.key =='||$1
doesn't it work ?
If no what is the error message

hey,thanks....i have got the result..... :)


got one more problem------------------

i have declared a string variable with some value,i want to check whether that string ends with "and" ....

how to do it in stored procedure----its like this

CREATE OR REPLACE FUNCTION test()
RETURNS varchar AS $$


DECLARE
samp varchar(400)
wr varchar;
index1 int;
begin
wr:='';
samp:=' (select * from tbl_usertable where a.ecpclaim_carr ier_id ILIKE
''PAPER'' and '

IF (samp.endsWith( ''and'')) then

index1:=samp.la stIndexOf(''and '');
samp:=samp.repl ace(index,lengt h(samp),'''');
end if;

IF (samp IS NULL) then
samp:=samp || wr;
end if;

return
end
$$ LANGUAGE 'plpgsql';

its showing error in "endsWith" and "lastIndexO f", so what are the functions we have to use in stored procedure of postgre for the functions "endsWith" and "lastIndexOf"?? ?????

help me out plz.........

Regards
Shree
Dec 13 '07 #5
rski
700 Recognized Expert Contributor
hey,thanks....i have got the result..... :)


got one more problem------------------

i have declared a string variable with some value,i want to check whether that string ends with "and" ....

how to do it in stored procedure----its like this

CREATE OR REPLACE FUNCTION test()
RETURNS varchar AS $$


DECLARE
samp varchar(400)
wr varchar;
index1 int;
begin
wr:='';
samp:=' (select * from tbl_usertable where a.ecpclaim_carr ier_id ILIKE
''PAPER'' and '

IF (samp.endsWith( ''and'')) then

index1:=samp.la stIndexOf(''and '');
samp:=samp.repl ace(index,lengt h(samp),'''');
end if;

IF (samp IS NULL) then
samp:=samp || wr;
end if;

return
end
$$ LANGUAGE 'plpgsql';

its showing error in "endsWith" and "lastIndexO f", so what are the functions we have to use in stored procedure of postgre for the functions "endsWith" and "lastIndexOf"?? ?????

help me out plz.........

Regards
Shree
I think position() function might help, but for more info see here
http://www.postgresql.org/docs/8.2/i...ns-string.html
Dec 13 '07 #6
Shree111
10 New Member
I think position() function might help, but for more info see here
http://www.postgresql.org/docs/8.2/i...ns-string.html

ya,got the result..thanks a lot.......

got one more issue.....

how to check case for a string in stored procedure....

i want to use equalsIgnoreCas e().....i thinks this string function is not available in postgreSQL....s o how can i check case for string here......give me the syntax plz

Regards
Shree
Dec 14 '07 #7
rski
700 Recognized Expert Contributor
ya,got the result..thanks a lot.......

got one more issue.....

how to check case for a string in stored procedure....

i want to use equalsIgnoreCas e().....i thinks this string function is not available in postgreSQL....s o how can i check case for string here......give me the syntax plz

Regards
Shree
I'm not suer if understand whatvyou want, but if you want to compare strings without case senstitive ins SQL queries you can use ILIKE operator, or you can user upper() or lower() functions.
Dec 14 '07 #8
Shree111
10 New Member
I'm not suer if understand whatvyou want, but if you want to compare strings without case senstitive ins SQL queries you can use ILIKE operator, or you can user upper() or lower() functions.

Acually,i want to check the condition like this.......

if((sReceiverTy pe IS NOT NULL) AND (sReceiverType= 'paper')) then

-----------some statement here---------

end if;


if input of "sReceiverT ype" is 'PAPER' then this condition will be false...

so,i want to ingnore case.......

which is like this in java class-------
sReceiverType.e qualsIgnoreCase ("paper");

so,what string function we have to use to do the same.....?????? ?


thanks and Regards
Shree
Dec 15 '07 #9
rski
700 Recognized Expert Contributor
Acually,i want to check the condition like this.......

if((sReceiverTy pe IS NOT NULL) AND (sReceiverType= 'paper')) then

-----------some statement here---------

end if;


if input of "sReceiverT ype" is 'PAPER' then this condition will be false...

so,i want to ingnore case.......

which is like this in java class-------
sReceiverType.e qualsIgnoreCase ("paper");

so,what string function we have to use to do the same.....?????? ?


thanks and Regards
Shree
Maybe like this (it's the simples solution)
if((sReceiverTy pe IS NOT NULL) AND (lower(sReceiver Type)='paper')) then
Dec 15 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1689
by: mmm, Pie | last post by:
I never ever thought about this, but recently I made a query in access so I can make a customer mailing list based on relational information and it was so easy to make the query and join tables and assign criterea using access. And I haven't tried or thought about this cause in my own small asp projects I've never used a dbase with queries in it, but after seeing how easy it was, it would save a lot of time from manually writting queries in...
2
5393
by: Satvic | last post by:
Hi all, Sorry for HTML, there is a lot of code & comments I tried to create a stored procedure from 3 queries .. to reduce # of times DB gets access from 1 asp page. The result procedure only works 1/2 way (does return the rest of the SELECT statement) :( Please help me figure out what stops it mid way? I need it to return all the results from the SELECT statements AND the number of rows (ScriptsNo) from the count(*): Here is...
8
15228
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental differences between a view and a query, or rather, when it is more appropriate to use one vs. the other. It seems to me that most select queries can be implemented as views, and I can't see the downside to doing so.
3
16940
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
13
5891
by: Anton.Nikiforov | last post by:
Hello everybody! Does someone know how to build hierarchical queries to the postgresql? I have a table with tree in it (id, parent) and need to find a way from any point of the tree to any other point. And i would like to have a list of all steps from point A to point B to make some changes on each step (this is required by the algorythm). Here is an example:
3
2139
by: Zlatko | last post by:
A question concerning Access Project with SQL Server: I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter rows to be updated or inserted into other tables. Filtration is based on certain actual values on forms (form with several subforms). My question is following: How to pass parameters to...
2
1440
by: rooster575 | last post by:
Im running a querystring in vb.net and it seems as though SQL server decides on the order in which to run the 3 queries in the string.. Is this possible? I would think that SQL server starts with the 1st query, executes it, then goes to the next. For example: ************************************************************ Dim myQueryString as string = _ "INSERT INTO ArchivedClients(ClientNo,ClientName) " & _ "SELECT ClientNo,ClientName...
0
1398
by: audleman | last post by:
I have an ASP form on my website where a visitor enters information. On submit, the form calls a stored procedure stores in a MS SQL 2000 database. The stored procedure works most of the time, but every once in a while I get an error 3421 (Application uses a value of the wrong type for the current operation) when I try to append the last parameter in the ASP code, which is a Varchar(500). Here's the relevant code: STORED PROCEDURE...
4
2893
by: enginious | last post by:
Hi, I'm sure I'm asking a very easy question, but I am currently in the process of migrating from MS SQL to PostgreSQL and I am facing a few issues, which I would appreciate your help/advice on : 1. Is there a way to overcome what seems to be everything turning to lowercase in a query? For example this was the original stored procedure in MS SQL : CREATE PROCEDURE sp_GetMessages @UserID Int,@ReadStatus1 int,@ReadStatus2 int AS...
0
8469
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.